Why does my string comparison fail?

后端 未结 4 768
予麋鹿
予麋鹿 2020-12-21 10:50

Let\'s say I have the following code and output:

for (j = 0; j <= i; j++) 
    printf(\"substring %d is %s\\n\", j, sub_str[j]);

4条回答
  •  滥情空心
    2020-12-21 11:27

    You can't use == to compare strings in C. You must use strcmp.

    for (j=0; j<=i; j++) { 
       if (strcmp(sub_str[j], "max_n=20") == 0) { 
          printf("substring %d is %s\n", j, sub_str[j]); 
       } 
    } 
    

提交回复
热议问题