小编sha*_*sid的帖子

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

我正在编写一个程序来比较两个字符串而不使用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 …
Run Code Online (Sandbox Code Playgroud)

c string c-strings strcmp

0
推荐指数
1
解决办法
109
查看次数

标签 统计

c ×1

c-strings ×1

strcmp ×1

string ×1