#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
char xx[80];
char delwords[5][21]={"a","is","in","the","an"};
void ReverseWord(void)
{ int j,k,len;
char *p,word[21];
char buf[80], str[80];
memset(buf,0,80);
memset(str,0,80);
p=xx[20];
j=0;
memset(word,0,21);
while(*p){
if(isalpha(*p))
{word[j++]=*p++;
if(*p)continue;
}
for(k=0;k<5;k++)
{if(stricmp(word,delwords[k])==0)
break;
}
if(k==5)
{len=strlen(word);
if(len>=5)
{if(islower(word[0]))
word[0]=toupper(word[0]);
}
strcpy(buf,word);
strcat(buf," ");
strcat(buf,str);
strcpy(str,buf);
}
j=0;
memset(word,0,21);
while(*p&&(!isalpha(*p)))
p++;
}
strcpy(xx[80],str);
}
void main()
{char xx[80]={"today is sunny you know?"};
ReverseWord();
printf("%s",xx[80]);
}
參考答案:两个错误:
1、p=xx[20];
p是指针,xx[20]是字符,不可赋值。
2、strcpy(xx[80],str);
strcpy需要字符数组或指针为参数,而xx[80]不是