Segmentation fault while copying the string Segmentation fault while copying the string unix unix

Segmentation fault while copying the string


char* ipStr[9];

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);}