关于strcmp()程序的C代码有什么问题?

sha*_*sid 0 c string c-strings strcmp

我正在编写一个程序来比较两个字符串而不使用strcmp().但是,我无法得到我想要的结果.这是我的程序的代码.

#include<stdio.h>
int main(int argc, char const *argv[]) {
   int i,j;
   char a[90],b[90];
   printf("Enter the first string:");
   scanf("%s", &a[90]);
   printf("Enter the second string:");
   scanf("%s", &b[90]);
   for ( i = 0; a[i] != '\0' && b[i] != '\0'; i++) {
      if (a[i] == b[i]) {
         /* code */
         printf("Equal %d \n", a[i]-b[i]);
continue;
      } if (a[i] > b[i]) {
         /* code */
         printf("ai is big %d \n", a[i]-b[i]);
         break;
      }
      if (a[i] < b[i]) {
         /* code */
         printf("%d bi is the biggest \n", a[i]-b[i]);
         break;
      }

   }


   return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我在终端中执行程序时,编译器接受输入字符串然后停止.我尝试了很多,但我无法弄清楚.谁能帮我吗...!

Lig*_*ica 7

你的第一个数组的名称a不是a[90].

同样,第二个数组的名称b不是b[90].

表达a[90]b[90]结束后的名字一个元素ab.

因此,通过写入&a[90]&b[90]指示每个数组之后scanf编写,这非常糟糕和错误.

你大概意思&a[0]&b[0]

但是,scanf非常危险,你根本不应该使用它.