-
how to compare 2 strings
hi i am new to programming in c ,
and i wanne know how to compare 2 strings
one string should be true keyboard input "gets(a);
and the other string i wanne read from a .txt file with fgets(b,30,f)
if (strcmp(a,b)==0) dont work cause the value of strcmp is 1 ore -1
how to set it to 0 and see if the strings are equal ?
sorry for my bad english .
greetings GMK0000
-
See, gets and fgets work differently. The first ignores the newline character while the second adds it to the string. I suggest using fgets for both the console and file input. Like this:
Code:
fgets(a, 30, stdin);
-
thanx for your reaction i am gonne try it out tonight
p.s.
you really devoted your life to program ? hahaha
if so let me add you as a friend
-
works perfectly thanx mate.
-
You really should forget that you've even heard of the gets() function. This function can never be safely used and has even been removed from the current C standard.
Jim