计算机等级考试三级网络技术|计算机等级考试三级网络技术上机考前必看4

更新时间:2019-05-02    来源:计算机等级考试    手机版     字体:

【www.kwkids.com--计算机等级考试】

计算机等级考试三级网络技术上机考前必看4

第一考试网整理了计算机等级考试三级网络技术上机考前必看

计算机等级考试三级网络技术上机考前必看(4)

试题四:函数ReadDat()实现从文件ENG.IN中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptChar(),按给定的替代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数WriteDat()把结果xx输出到文件PS5.DAT中。

替代关系:f(p)=p*11mod 256 (p是数组中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果计算后f(p)值小于等于32或f(p)对应的字符是小写字母,则该字符不变,否则将f(p)所对应的字符进行替代。

注意:部分源程序已给出。原始数据文件存放的格式是:每行的宽度均小于80个字符。

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

------------------------------

PROG1.C

#include

#include

#include

#include

unsigned char xx[50][80];

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

int ReadDat(void);

void WriteDat(void);

void encryptChar()

{

}

void main()

{

clrscr();

if(ReadDat()){

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

return;

}

encryptChar();

WriteDat();

system("pause");

}

int ReadDat(void)

{

FILE *fp;

int i=0;

unsigned char *p;

if((fp=fopen("eng.in","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("ps5.dat","w");

for(i=0;i

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

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

}

fclose(fp);

}

/*标准答案*/

void encryptChar()

{int I;

char *pf;

for(I=0;I

{pf=xx[I];

while(*pf!=0)

{ if ((*pf*11%256>="a"&&*pf*11%256<="z")||*pf*11%256<=32)

{pf++;continue;}

*pf=*pf*11%256;

pf++;} }

}

或者:

void encryptChar()

{int i,j,t;

for(i=0;i

{for(j=0;j

{t=xx[i][j]*11%256;

if(t<=32 ||(t>="a" && t<="z")) continue;

xx[i][j]=t;}}

}

本文来源:http://www.kwkids.com/jisuanjilei/16802.html

热门标签

更多>>

本类排行