计算机等级考试三级编程解析十

文章作者 100test 发表时间 2007:03:10 18:23:08
来源 100Test.Com百考试题网


十、字符串(单词)的倒置和删除

  函数READDAT()实现从文件IN.DAT中读取一篇英文文章存入到字符串数组XX中.请
编制函数STROR(),其函数功能是:以行为单位把字符串中的所有小写字母O左边的字符串
内容移到该串的右边存放,然后并把小写字母O删除,余下的字符串内容移到已处理字符串
的左边存放.最后把已处理的字符串仍按行重新存入字符串数组XX中,最后调用函数WRIT
EDAT()把结果XX输出到文件OUT5.DAT中.
例如:原文:You can create an index on any field.
you have the correct record.
结果: n any field.You can create an index
rd.yu have the crrect rec
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格.
# include"stdio.h"
# include"string.h"
# include"conio.h"
# include"ctype.h"
# include"mem.h"
unsigned char xx[50][80].
int maxline=0.

int readdat(void).
void writedat(void).

void StrOR(void)
{

}

void main()
{
clrscr().
if(readdat())
{printf("Can’t open the file ENG.IN!\n").
return.
}
StrOR().
writedat().
}

int readdat(void)
{
FILE *fp.
int i=0.
char *p.
if((fp=fopen("in.dat","r"))==NULL)
return 1.
while(fgets(xx[i],80,fp)!=NULL)
{p=strchr(xx[i],’\n’).
if(p)
*p=0.
i .
}
maxline=i.
fclose(fp).
return 0.
}

void writedat(void)
{FILE *fp.
int i.
fp=fopen("out5.dat","w").
for(i=0.i{printf("%s\n",xx[i]).
fprintf(fp,"%s\n",xx[i]).
}
fclose(fp).
}


相关文章


计算机等级考试三级编程解析十二
计算机等级考试三级编程解析九
计算机等级考试三级编程解析十
计算机等级考试三级编程解析七
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛