string - Two identical chains do not identify themselves as equals in C -


i've 2 character strings, 1 first line of file (which "working"), , second word "working". problem when try put them in if, says they're not same!

i've tried read both of them printf command they're same. i've tried use '\n' in second string there's not change.

here's code, have look:

file *fl; fl=fopen("test.txt", "r"); char line_working[100]; fscanf(fl, "%s\n", line_working); fclose(fl); printf("%s", line_working);              //here prints: working char* workinger="working"; printf("\n%s", workinger);               //here prints: working getch(); if(workinger==line_working){     printf("ok");     getch(); } 

and nothing happens...

== compares pointer addresses.

to compare null-terminated character arrays (aka c-strings), use strcmp:

if(strcmp(workinger, line_working) == 0) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -