I am having trouble writing input from stdin to an array of strings in C. Forgive me if this is trivial but I really hate dealing with strings, they seem easy but never work for me. Here is some code fragments
I get seg faults in the strcpy call. I have tried using memcpy/memmove with n=strlen(buf) but the same problem occurs. Any hints?
char *buf, **data;
data = calloc( ELEM_INIT, CHARS_INIT );
buf = malloc( MAXBUF );
assert( buf != NULL && data != NULL);
while( fgets( buf, MAXBUF-1, stdin ) != NULL && i < ELEM_INIT)
strcpy( data[i], buf );