c语言不用函数实现strcmp()输入相同字符串时比较不正确

c语言不用函数实现strcmp()输入相同字符串时比较不正确

//strcmp函数
#include<stdio.h>
void main()
{
    int i=0,re,m,n;
    char str1[1000],str2[1000];
    printf("请输入字符串str1:");
    gets(str1);
    printf("请输入字符串str2:");
    gets(str2);
    do
    {
        i++;
        if(str1[i]==str2[i])
            {
                re=0;
                continue;
            }
        else if(str1[i]>str2[i])
            {
                re=1;
                break;
            }
        else if(str1[i]<str2[i])
            {
                re=-1;
                break;
            }
    }while(i<1000);
    printf("%d\n",i);
    printf("%d\n",re);
    if(re==1)
        printf("字符串str1大于字符串str2");
    if(re==-1)
        printf("字符串str1小于字符串str2");
    if(re==0)
        printf("字符串str1等于字符串str2");

}

图片说明

#include<stdio.h>
void main()
{
    int i=0,re=0,m,n;
    char str1[1000],str2[1000];
    printf("str1:");
    gets(str1);
    printf("str2:");
    gets(str2);
    do
    {
        if (!str1[i] && !str2[i])
            {
                re=0;
                break;
            }
        else if(str1[i]>str2[i] || !str2[i])
            {
                re=1;
                break;
            }
        else if(str1[i]<str2[i] || !str1[i])
            {
                re=-1;
                break;
            }
        i++;
    }while(i<1000);
    printf("%d\n",i);
    printf("%d\n",re);
    if(re==1)
        printf(">");
    if(re==-1)
        printf("<");
    if(re==0)
        printf("==");

}

问题解决请采纳