segmentation fault.....
i made a lzw compression program......when i execute it it gives segmentation fault......sum1 told me it might be d problem of memory area of user and kernel.......n told me to use debugger ........can sum1 help me learn how is debugger used...or any other alternative.......
|
Quote:
Quote:
Quote:
The suggestion of "using a debugger" is excellent advice. Quote:
http://heather.cs.ucdavis.edu/~matlo...age/Debug.html PS: Is it really that difficult to spell out words, write in complete sentences, or use capitalization and punctuation? |
Quote:
... char *str; char t; t=fgetc(in); strcat(str,&t); .... .. |
You never allocated the string that you are pointing to with str.
Either: char *str; char t; str = calloc(1,numberofbytesneeded); t=fgetc(in); strcat(str,&t); or char str[numberofbytesneeded]; char t; t=fgetc(in); strcat(&str[0],&t); I used calloc because you probably need a null termination in your string. If you use the second form I gave, you'll have to either write the 0x0 at the end or use memset to clear str before using it. edit: Also, many people (myself included) are far more likely to respond when you employ correct grammar and punctuation. |
Quote:
... ... char *atr; char t; t=fgetc(in); *str=t; .. .. I used this one ...and tried in TURBO C....It gave it this way....NULL POINTER ASSIGNEMENT....not at this line no...but at the end of main()........And GCC still gave "segmentation fault".... |
Try
str = &t; though I am not sure this is what you want. |
Quote:
|
Problem 1: if you're going to use a string, then you need to allocate *space* for the string. Jiml8 suggested a couple of great alternatives.
Problem 2: If you're going to use "stcat", "strcpy" and friends, you should really use *two strings* (not a string and a character). Code:
/* Bad */ Code:
#include <stdio.h> Quote:
|
Quote:
|
Hi -
1. What exactly are you trying to do? 2. How far have you gotten? 3. What's going wrong at that point? SUGGESTIONS: * Create a new thread * Try to be as explicit as you can about each of these three questions. Good luck .. PSM PS: One more suggestion: * If you're on Linux, you're programming in C/C++, and you're using gcc or g++, then... * Compile and link with "-g" (full debugging on), and ... * run your program from gdb (the command-line GCC debugger) * when your program crashes, do a "where" (or, equivalently, "bt") <= This will give you a "stack traceback" ... a *vital* clue as to where the error is occurring, and what should be done to debug it * Cut/paste this "stack traceback" into your post Again - good luck! http://www.cs.cmu.edu/~gilpin/tutorial/ http://heather.cs.ucdavis.edu/~matlo...age/Debug.html |
All times are GMT -5. The time now is 09:17 PM. |