c - Why does this code always print "not matched"? -


#include <stdio.h>  int main(int argc, char const *argv[]) {     file *ls = popen("tmp.sh", "r");     char char_array[256];     while (fgets(char_array, sizeof(char_array), ls) != 0) {        //nop     }     char *ptr_somechar = &char_array[0];     char *pointer = "high";     if (strcmp(pointer, ptr_somechar) == 0)      {          printf("%s\n", "match");     } else      {          printf("%s\n", "not matched");     }     pclose(ls);     return 0; } 

i want compare output line. tmp.sh returns "high". why code print "not matched"?

it seems string "high" in file followed newline character , fgets reads \n too. need remove character before comparison.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -