C语言编程问题----急()

来源:百度知道 编辑:UC知道 时间:2024/06/08 04:53:52
一个删除单词的问题:
#include "stdio.h"
main()
{ void count(char *p);
void delete(char words[],char del[]);
char words[100],del[10];
printf("Please input the words:\n");
gets(words);
count(words);
printf("Please input the word you want to delete:\n");
gets(del);
delete(words,del);
count(words);
getch();
}
void count(char *p)
{
int i,test=0,num=0;
for(i=0;*(p+i)!='\0';i++)
{
if(*(p+i)==' ')
test=0;
else if(test==0)
{
test=1;
num++;
}
}
printf("now total words: %d\n",num);

}
void delete(char words[],char del[])
{ int x,i,j,k,t;
for(i=0;words[i]!='\0';)
{ x=j=i;k=0;
w

乍一看程序大体框架是对的,能不能说说具体问题所在.

this is a dog.实现了删除单词,说明基本功能有了.
输入a删除aa是因为你没有对单词做判断,在delete中,只要遇到输入要删的字符串,则删除.例如你输入dogdog的话,再输入dog,他也会把dogdog整个删除掉的.
建议你在delete函数中修改,增加对单词的判断,即遇到输入的字符串后,看其后是不是空格符,若是,则删除,若不是,则不删除.那样功能就完善了.

语法错误的厉害!