Why does my string comparison fail?

后端 未结 4 769
予麋鹿
予麋鹿 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条回答
  •  猫巷女王i
    2020-12-21 11:31

    You can't compare strings in C with == operator. You need to use strcmp function or strncmp.

提交回复
热议问题