一道有点难搞的C语言题,200分

2024-12-05 00:00:35
推荐回答(2个)
回答1:

#include
#include
char *word[]={"from","in","at","an","on"};
#define NUM 5
#define LINES 256
#define MAXLEN 1000
main()
{
char *lineptr[LINES],*p;
int i,j,k,nlines;
if ((nlines=readlines(lineptr,100))>0)
{
for(i=0;i{
j=0;
while(j{
p=lineptr[j++];
while((k=index(p,word[i]))>=0)
del_word(p,k,strlen(word[i]));
}
}
writelines(lineptr,nlines);
}
}
del_word(char *s,int n,int len)
{
while(*(s+n)=*(s+n+len)) n++;
}
readlines(char *lineptr[],int maxlines)
{
int len,nlines=0;
char *p,line[MAXLEN];
printf("Input a paragraph:\n");
while ((len=getline(line,MAXLEN))>1)
if (nlines>maxlines)
return(-1);
else if ((p=malloc(len+1))==NULL)
return(-1);
else
{
line[len]='\0';
strcpy(p,line);
lineptr[nlines++]=p;
}
return(nlines);
}
getline(char *s,int len)
{
int c;
char *p=s;
while (--len>0 && (c=getchar())!='\n')
*s++=c;
*s='\0';
return(s-p);
}
writelines(char *lineptr[],int nlines)
{
int i;
printf("Show the paragraph:\n");
for (i=0;iprintf("%s\n",lineptr[i]);
}
index(char s[],char t[])
{
int i,j,k;
for(i=0;s[i]!='\0';i++)
{
for (j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++);
if (t[k]=='\0')
return(i);
}
return(-1);

回答2:

加百度hi 跟你说