【2006年全国房价】2006年9月全国等级考试三级c语言上机题库(十六)

试题集锦 2023-06-15 网络整理 可可

【shitiku.jxxyjl.com--试题集锦】

★题目16(无忧id 23 字符替换题)

 

函数readdat()实现从文件in.dat中读取一篇英文文章存入到字符串数组xx中,请编制函数strcharjr(),其函数的功能是:以行为单位把字符串中所有字符的ascii值右移4位,然后把右移后的字符ascii值再加上原字符的ascii值,得到新的字符仍存入原字符串对应的位置上。最后把已处理的字符串仍按行重新存入字符串数组xx中,最后调用函数writedat()把结果xx输出到文件out8.dat中。

原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。

部分源程序存在文件prog1.c中。

请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

char xx[50][80];

int maxline=0;/*文章的总行数*/

 

int readdat(void);

void writedat(void);

 

void strcharjr()

{int i,j;

for(i=0;i<maxline;i++)

for(j=0;j<strlen(xx[i]);j++)

xx[i][j]+=(xx[i][j]>>4);

}

 

void main()

{

clrscr();

if(readdat()){

printf("数据文件in.dat不能打开!\n\007");

return;

}

strcharjr();

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;

clrscr();

fp=fopen("out8.dat","w");

for(i=0;i<maxline;i++){

printf("%s\n",xx[i]);

fprintf(fp,"%s\n",xx[i]);

}

fclose(fp);

}

本文来源:https://shitiku.jxxyjl.com/shitijijin2/27228.html

Copyright @ 2011- 考试题库网 All Rights Reserved. 版权所有

免责声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。

 站长统计