C language, and then wait online. Eager, what s wrong

Updated on technology 2024-05-27
4 answers
  1. Anonymous users2024-02-11

    It is advisable to look at the basic structure of the program: order, select branches, loops.

    But look at your **, even the touch is also very big, I didn't expect ** to be able to write like this. can only write the ** on the book, and even a rookie

    The following ** can:

    #include

    #include

    #define n 256

    int mystrcmp(char* str1,char* str2)

    int i,r=-1;

    for(i=0;(*str1+i)!='\0' ||str2+i)!='\0');i++)

    if(*(str1+i)==*(str2+i))

    r=0;continue;It was originally broken; break jumps out of the loop directly, and the returned r is, of course, 0. But there are also cases where it is not equal, hehe. For example, "123" and "456".

    if(*(str1+i)>*str2+i))

    r=1;return r;///////

    if(*(str1+i)<*str2+i))

    r=2;return r;///////

    return r;

    int main()

    int r;

    char a[n],b[n];

    char *p=a,*q=b;

    printf("Please enter the first string:");

    scanf("%s",p);gets() doesn't compile on my machine.

    printf("Please enter the second string:");

    scanf("%s",q);

    r=mystrcmp(p,q);

    if(r==0)

    printf("The two strings are equal");

    if(r==1)

    printf("The first string is large");

    if(r==2)

    printf("The second string is large");

    return 0;

    Result: pig@pig-laptop: $gcc

    pig@pig-laptop:~$/

    Please enter the first string: abc

    Please enter the second string: abc

    The two strings are equal pig@pig-laptop: $

    Please enter the first string: aji

    Please enter the second string: aij

    The first string is large pig@pig-laptop: $

    Please enter the first string: aij

    Please enter the second string: aji

    The second string is large

  2. Anonymous users2024-02-10

    if(r==1)

    printf("The second string is large");

    if(r==2)

    printf("The first string is large");

    Change the part of your program to the above, because when comparing letters, a>b, but the ACII code of a is less than b, you are mainly making this mistake, and your program is correct.

  3. Anonymous users2024-02-09

    There is something wrong with the algorithm.

    In the for loop, only the first character of 2 strings is compared, so no matter what string is entered, only the first character is compared, and then the size of the entire string is judged based on the first character alone.

  4. Anonymous users2024-02-08

    You wrote this and broke after comparing only one character.

Related questions
8 answers2024-05-27

If you define r as int, enter 10000 and that will automatically force the type conversion when multiplied. >>>More

4 answers2024-05-27

No. txt file I don't know what you want to read in.

4 answers2024-05-27

Hello, there hasn't been much time lately, so I can only remind you that the focus of this zhi topic is not dao >>>More

18 answers2024-05-27

It's not low, but it's ......It's not worth the effort ...... this program