#include <stdio.h>
#include <stdlib.h>
char passage[5000][20];
char *getword(int i);
int main(){
passage[0][0] = 'a';
passage[0][1] = 'm';
passage[0][2] = '\0';
printf("%s\n", getword(0));
char *word = getword(0);
printf("%d", strcmp(word,"am"));
return 0;
}
char *getword(int i){ //get a word from passage
int a=0;
static char words[20];
while (passage[i][a] != ' '){
words[a] = passage[i][a];
a++;
//printf("%c\n",words[a]);
}
words[a] = '\0';
return words;
}
我计划通过从{2} function
获取string
并将string
与某个词进行比较,为array
进行比较string
。为什么strcmp
返回-1?它应该是相同的还是考虑null
?
答案 0 :(得分:0)
while (passage[i][a] != '\0'){
将此更改为
number
答案 1 :(得分:-2)
string equal return 0
第一个字符串是更高的返回1