好像陷入了死循环,是哪里出问题了呢?
我的代码:
#include <stdio.h>
#include <string.h>
int main()
{
char words[1001];
char word[101];
char nword[101];
char nwords[1001];
int i,j=0;
printf("请输入字符串:\n");
gets(words);
printf("请输入希望移除的词:\n");
gets(word);
for(i=0;words[i]!='\0';i++)
{
if (words[i]!=' ')
{
nword[j] = words[i];
j++;
}
if (words[i]==' ')
{
j=0;
if(strcmp(nword,word)==0)
{
strcat(nwords,nword);
}
nwords[strlen(nwords)]=' ';
strcpy(nword,'\0');
}
}
printf("移除%s后的字符串是:\n",word);
puts(nwords);
return 0;
}