天天看點

strcmp 字元串比較

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int strcmp_lx(char* str1,char* str2);

static int f = ;

int main()
{
    char* str1 = new char();
    char* str2 = new char();

    cout << "輸入第一個字元串" << endl;
    cin >> str1;
    cout << "輸入第二個字元串" << endl;
    cin >> str2;

    cout <<    strcmp_lx(str1,str2) << endl;

    delete str1;
    delete str2;
    return ;
}

int strcmp_lx(char* str1,char* str2)
{

    int i = ;

    while((*str1!='\0') && (*str2!='\0') && (*str1==*str2))
    {   
        *str1++;
        *str2++;
    }

    return *str1-*str2;
}
           

繼續閱讀