做好计算机考试复习工作需要大量的基础知识积累,为了帮助你在有效的时间内,拓展你的知识面,做大量试题巩固基础知识,我们考吧网整理了一些关于计算机三级网络技术上机练习题,希望你能够喜欢。
2013年计算机三级网络技术上机练习题13
读函数readDat()的功能是从文件IN76.DAT中读取20行数据存放到字符串数组xx中(每行字符串长度均小于80)。请编制函数jsSort(),该函数的功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组xx中,最后调用写函数writeDat()把结果xx输出到文件OUT76.DAT中。
条件:从字符串中间一分为二,左边部分按字符的ASCII值升序排序,排序后,左边部分与右边部分按例子所示进行交换。如果原字符串长度为奇数,则最中间的字符不参加处理,字符仍放在原位置上。
例如: 位置 0 1 2 3 4 5 6 7 8
源字符串 d c b a h g f e
4 3 2 1 9 8 7 6
处理后字符串 h g f e a b c d
9 8 7 6 1 2 3 4
注意:部分源程序已给出。
请勿改动主函数main()、读函数readDat()和写函数writeDat()的内容。
试题程序:
#include
#include
#include
char xx[20][80];
void readDat();
void writeDat();
void jsSort()
{
}
void main()
{
readDat();
jsSort();
writeDat();
}
void readDat()
{
FILE *in;
int i=0;
char *p;
in = fopen("IN76.DAT", "r");
while(i<20 && fgets(xx[i], 80, in) != NULL)
{
p = strchr(xx[i],'');
if(p) *p = 0;
i++;
}
fclose(in);
}
void writeDat()
{
FILE *out;
int i;
system("CLS");
out = fopen("OUT76.DAT", "w");
for(i=0; i<20; i++)
{
printf("%s", xx[i]);
fprintf(out, "%s", xx[i]);
}
fclose(out);
}