已知一个字符串中仅包含字母和空格,用空格来分割各个单词,求出其中最长的单词
#include <stdio.h>
int main(int argc, const char * argv[]) {
char *words ="word excel with if";
int length = sizeof(words)/sizeof(char);
int *nums = {1},clen = 0,enddex,i;
for(i = 1;i<length;i++){
if(words == ' ')
nums = 0;
else {
*(nums+i) = *(nums + i -1) + 1; //thread1:EXC_BAD_ACCESS(code=1,address=0x1)
if(nums>clen){
clen = nums;
enddex = i;
}
}
}
for(int j = 0;j<clen;j++)
printf("%c",*(words + i - clen +j));
return 0;
}
上面加粗这里的错误是什么意思,
|
|