c - Strcmp not returning 0 -


i have textfile looks this:

temp:88 tt:33 3d;3d:5 

i'm trying parse first line only, , check indeed "temp:88"

this tried:

file * file = fopen("test.txt","r");  if(file == null)     exit(0); char buff[128];  while(fgets(buff,sizeof(buff),file) != null) {      if(strcmp(buff,"temp:88") == 0)           printf("true");      else          printf("false"); //prints false, regardless of newline character, use of memcopy or else      break; } 

then tried add new line character "\n" inside strcmp yielded same results, , mem copy yielded same result, ideas?

from below source code

file * file = fopen("test.txt","r"); if(file == null)     exit(0); char buff[128];  while(fgets(buff,sizeof(buff),file) != null) {     printf("%s,%d\n",buff,strlen(buff));     int i= 0;     while(i<strlen(buff))     {         printf("%d\n",buff[i]);         i++;     }     if(strcmp(buff,"temp:88") == 0)          printf("true");     else         printf("false"); //prints false, regardless of newline character, use of memcopy or else     break; } 

its out put is,

$ ./a.exe temp:88 ,9 84 69 77 80 58 56 56 13 10 false

this ascii values , string length shows read string not "temp:88". read buffer contain ascii values of lf , cr @ end.

so can use

strncmp(buff,"temp:88",strlen("temp:88")); 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -