| 
 | 
 
5鱼币 
大家号,为什么程序运行后没有结果呢? 
- #include<stdio.h>
 
 - #include<stdlib.h>
 
 - #include<string.h>
 
  
- #define MAX 1024
 
 - int main()
 
 - {
 
 -         char str1[MAX];
 
 -         char str2[MAX];
 
 -         int n,m,i=0;
 
 -         
 
 -         printf("请输入第一个字符串:\n");
 
 -         while ((str1[i++] = getchar()) != '\n');
 
 -         
 
 -         printf("请输入第二个字符串:\n");
 
 -         while ((str2[i++] = getchar()) != '\n');
 
 -         
 
 -         printf("请输入要比较的位数:\n");
 
 -         scanf("%d",&n);
 
 -         
 
 -         if (!strncmp(str1, str2, n))
 
 -         {printf("两字符串前%d个字符相同",n);}
 
 -         
 
 -         system("pause");
 
 -         return 0;
 
 -         } 
 
  复制代码 
 
 
 
不好意思,我看错了。你第二个输入i,没有归0; - #include<stdio.h>
 
 - #include<stdlib.h>
 
 - #include<string.h>
 
  
- #define MAX 1024
 
 - int main()
 
 - {
 
 -         char str1[MAX];
 
 -         char str2[MAX];
 
 -         int n,m,i=0;
 
 -         
 
 -         printf("请输入第一个字符串:\n");
 
 -         while ((str1[i++] = getchar()) != '\n');
 
 -         
 
 -         i = 0;
 
  
-         printf("请输入第二个字符串:\n");
 
 -         while ((str2[i++] = getchar()) != '\n');
 
 -         
 
 -         printf("请输入要比较的位数:\n");
 
 -         scanf("%d",&n);
 
 -         
 
 -         if (!strncmp(str1, str2, n))
 
 -         {printf("两字符串前%d个字符相同",n);}
 
 -         
 
 -         system("pause");
 
 -         return 0;
 
 -         }
 
  复制代码 
 
 
 |   
 
 
最佳答案
查看完整内容 
不好意思,我看错了。你第二个输入i,没有归0; 
 
 
 
 
 
 
 |