String Comparison Discrepancy (Works for some cases and sometimes doesn’t)
我使用以下代码测试了我收到的电子邮件文件中的一些文本检测。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include <stdio.h>
int main() char user1[7] ="string1"; // 23 while (pointer != max_size && chk != 1) for (j = 0;j<7; j++) if (strcmp(found1, user1) == 0){ for (j = 0;j<7; j++) if (strcmp(found2, user2) == 0){ for (j = 0;j<7; j++) if (strcmp(found3, user3) == 0){ for (j = 0;j<7; j++) if (strcmp(found4, user4) == 0){ for (j = 0;j<7; j++) if (strcmp(found5, user5) == 0){ pointer++; } |
我使用上述代码在电子邮件正文中查找特定用户。如果找到用户,while 循环将中断。当我尝试运行它时,我在上面的变量 (email)
中包含了不同的字符串
我首先尝试在不同的在线 C 编译器上运行它。他们都有字符串 1,3 和 5 工作正常。 (被检测到)
其中一些字符串 2 工作正常(被检测到)。
然而,他们都分享了 string2 从未被检测到的事实。我不知道为什么。我试着想一个原因,但不知道为什么。
非常感谢您的帮助。
1
|
char found1[7] ="string1";
|
这里
1
|
char found1[8] ="string1";
|
您将
或者正如@Barak Manos 建议的那样,你可以去
1
|
char found1[] ="string1";
|
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/269287.html