The above creates an array of 9 strings (pointers to char ). It does not, however, allocate memory for the nine strings.
Up vote 4 down vote favorite share g+ share fb share tw.
I am trying to execute the below code, but for every attempt I am geting a segmentation fault. The problem seems to be coming from the strncpy function used in tokenizing. I a bit new to programming.
Please help me debug the code. Please help: /* ** Program to accept a binary IP address from the command line and ** if it is a valid IP address, show the user its dotted decimal form. ** Also tell the user, which class of IP address it belongs to */ #include #include #include #define TRUE 1 #define FALSE 0 int validchk(char uarg); int tokenize(char uarg, char* uargv); int toNum(char harr, char iparr); void shownum(char *iparr); void classify(char uarg); void usage(); void mystrncpy(char* arr, char* brr); int main(int argc, char *argv) { char* ipStr9; if (argc!
= 2) { usage(); exit(1); } if (validchk(argv1) == FALSE) { fprintf(stderr,"Error in the length of the IP Bit Address\n"); exit(1); } classify(argv1); if (tokenize(argv1,ipStr) == -1) { perror("Error in tokenizing the binary IP address\n"); } //shownum(ipStr); return 0; } void usage() { fprintf(stderr,"Usage: bi2ip \n"); return; } int validchk(char uarg) { if (strlen(uarg)! = 32) { return FALSE; } } void classify(char uarg) { int ipcnt = 0; char *p; int doneflag = FALSE; while(ipcnt.
Char* ipStr9; The above creates an array of 9 strings (pointers to char). It does not, however, allocate memory for the nine strings. When you strncpy into ipStr, your program segfaults.
Solution: allocate memory (e.g. Using malloc() or strdup()).
Your validchk() function fails to return TRUE if the address validates. This will make it behave more or less randomly. You should rewrite it, keeping the same core validation rule, as: int validchk(const char *string) { return (string!
= NULL) && (strlen(string) == 32); }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.