debugging - Segmentation fault strcmp in c -
i'm trying run program in c takes in text file , string user , searches file string. keeps getting segmentation fault , gdb pointing me towards function not sure problem is. pretty sure has strcmp call not sure. issue appreciated.
int intable( const char *s ) { int i; for( i=0; i<numlines; ++i ) { if( strcmp( st[i], s ) == 0 ) return 1; } return 0; }
you should check use strcmp(), api is:
int strcmp(const char *str1, const char *str2) you must:
1) validate st[i], first argument pointer.
2) make sure st[i] & s has null terminator '\0'`.
3) check st[i] & s pointing allocated place in memory before calling strcmp().
Comments
Post a Comment