完成后,用户应输入一些字符串并输入空格作为字符串。代码应返回输入的最长和最短的单词。
strcmp 总是返回-1 ...我做错了什么?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char S[100][20];
int I = 0;
do {
cout << "Enter text:" << endl;
cin.getline(S[I],100);
} while (I < 19 && strcmp(S[I++],""));
char Max[100], Min[100];
strcpy(Max, S[0]);
strcpy(Min, S[0]);
for (int J = 1; J < I; J++) {
if (strcmp(S[J], Max) == 1)
strcpy(Max, S[J]);
if (strcmp(S[J], Min) == -1)
strcpy(Min, S[J]);
}
cout << "Max = " << Max << endl;
cout << "Min = " << Min << endl;
system("pause");
return 0;
}