函數(shù)ReadDat()實(shí)現(xiàn)從文件ENG.IN中讀取一篇英文文章存入到
字符串?dāng)?shù)組xx中; 請(qǐng)編制函數(shù)DelWord()分別按行刪除空格、標(biāo)點(diǎn)
符號(hào)以及10個(gè)不區(qū)分大小寫的英文單詞(you,for,your,on,no,if,
the,in,to,all), 余下的單詞按順序重新存入數(shù)組xx中, 最后調(diào)用
函數(shù)WriteDat()把結(jié)果xx輸出到文件PS6.OUT中。
例如: 原文: You are a student.
結(jié)果: areastudent
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符, 含
標(biāo)點(diǎn)符號(hào)和空格。
注意: 部分源程序存放在PROG1.C中。文章每行中的單詞與單
詞之間用空格或其它標(biāo)點(diǎn)符號(hào)分隔, 每單詞均小于20個(gè)字符。
請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函
數(shù)WriteDat()的內(nèi)容。
/*參考答案*/
#include
#include
#include
#include
char WORD[10][10] = {"you", "for", "your", "on", "no","if","the","in","to","all"} ;
char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數(shù) */
int ReadDat(void) ;
void WriteDat(void) ;
void DelWord(void)
{
int i,j,k,n,len;
char word[20],c;
char str[80];
for(i = 0; i < maxline; i++)
{
len = strlen(xx);
memset(str,0,80*sizeof(char));
n = 0;
for(j = 0; j < len+1; j++)
{
c = xx[j];
if((c>=’a’ && c<=’z’) || (c>=’A’ && c<=’Z’))
{
word[n] = c;
n++;
}
else
{
word[n] = ’\0’;
if(word[0] != ’\0’)
{
for(k = 0; k < 10; k++)
if(strcmpi(WORD[k],word) == 0)
break;
if(k >= 10)
strcat(str,word);
}
n = 0;
}
}
len = strlen(str);
memcpy(xx,str,len+1);
}
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007") ;
return ;
}
DelWord() ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;
字符串?dāng)?shù)組xx中; 請(qǐng)編制函數(shù)DelWord()分別按行刪除空格、標(biāo)點(diǎn)
符號(hào)以及10個(gè)不區(qū)分大小寫的英文單詞(you,for,your,on,no,if,
the,in,to,all), 余下的單詞按順序重新存入數(shù)組xx中, 最后調(diào)用
函數(shù)WriteDat()把結(jié)果xx輸出到文件PS6.OUT中。
例如: 原文: You are a student.
結(jié)果: areastudent
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符, 含
標(biāo)點(diǎn)符號(hào)和空格。
注意: 部分源程序存放在PROG1.C中。文章每行中的單詞與單
詞之間用空格或其它標(biāo)點(diǎn)符號(hào)分隔, 每單詞均小于20個(gè)字符。
請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函
數(shù)WriteDat()的內(nèi)容。
/*參考答案*/
#include
#include
#include
#include
char WORD[10][10] = {"you", "for", "your", "on", "no","if","the","in","to","all"} ;
char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數(shù) */
int ReadDat(void) ;
void WriteDat(void) ;
void DelWord(void)
{
int i,j,k,n,len;
char word[20],c;
char str[80];
for(i = 0; i < maxline; i++)
{
len = strlen(xx);
memset(str,0,80*sizeof(char));
n = 0;
for(j = 0; j < len+1; j++)
{
c = xx[j];
if((c>=’a’ && c<=’z’) || (c>=’A’ && c<=’Z’))
{
word[n] = c;
n++;
}
else
{
word[n] = ’\0’;
if(word[0] != ’\0’)
{
for(k = 0; k < 10; k++)
if(strcmpi(WORD[k],word) == 0)
break;
if(k >= 10)
strcat(str,word);
}
n = 0;
}
}
len = strlen(str);
memcpy(xx,str,len+1);
}
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007") ;
return ;
}
DelWord() ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;