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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -