阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。【C语言程序】include<stdio.h>main(){FILE *oldf,*newf;char ch,fname[20];int i;do{printf("Enter name of existed text file to be read:");scanf("%s",fname);if((oldf=fopen(fname,"r"))==NULL)printf("File %s can't open!\n",fname);}while(oldf==NULL);do{printf("Enter mane of new text file to be written:");scanf("%s",fname);if(((1)==NULL)printf("File %s can't open!\n",fname);}while((2));i=1;while(!feof(oldf)){while((ch=fgetc(oldf))!=(3)){if(i%2==(4))fputc(ch,newf);}fputc('\n',newf);(5);}fclose(oldf);fclose(newf);}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

【说明】

编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。

【C语言程序】

include<stdio.h>

main()

{

FILE *oldf,*newf;

char ch,fname[20];

int i;

do{

printf("Enter name of existed text file to be read:");

scanf("%s",fname);

if((oldf=fopen(fname,"r"))==NULL)

printf("File %s can't open!\n",fname);

}while(oldf==NULL);

do{

printf("Enter mane of new text file to be written:");

scanf("%s",fname);

if(((1)==NULL)

printf("File %s can't open!\n",fname);

}while((2));

i=1;

while(!feof(oldf))

{

while((ch=fgetc(oldf))!=(3))

{

if(i%2==(4))

fputc(ch,newf);

}

fputc('\n',newf);

(5);

}

fclose(oldf);

fclose(newf);

}


相关考题:

●试题四阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。【函数】void QuickSort(int A[],int s,int t){int i=s,j=t+1,temp;int x=A[s];do{do i++;while (1) ;do j--;while(A[j]x);if(ij){temp=A[i]; (2) ; (3) ;}}while(ij);A[a]=A[j];A[j]=x;if(si-1) (4) ;if(j+1t) (5) ;}

阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。【说明】函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。【函数】void QuickSort( int A[ ],int s,int t){ int i=s,j=t+1,temp;int x=A[s];do{do i ++ ;while (1);do j -- ;while(A[j]>x);if(i<j){temp=A[i];(2);(3);}}while(i<j);A[a] =A[j];A[j] =x;if(s<i-1) (4);if(j+1<t) (5);}

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]完成以下中序线索化二叉树的算法。[函数]Typedef int datatype;Typedef struct node {Int ltag, rtag;Datatype data;*lchild,* rchild;}bithptr;bithptr pre;void inthread ( p );{if{inthread ( p->lchild );if ( p->lchild==unll ) (1);if ( P->RCHILD=NULL) p->rtag=1;if (2){if (3) pre->rchild=p;if ( p->1tag==1 )(4);}INTHREAD ( P->RCHILD );(5);}}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。【函数】int fun(char *c,int status){if((1)=='')return 1;else{if((2)(3)(4))(5)='A'-'a';return 0;}}main(){int flag=1;char ch;printf("请输入一字符串,用点号结束输入!\n");do {ch=getchar();flag=fun(ch,flag);putchar(ch);}while(ch!='.');printf("\n");}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在答题纸的对应栏内。【函数2.1说明】递归函数sum(int a[], int n)的返回值是数组a[]的前n个元素之和。【函数2.1】int sum (int a[],int n){if(n>0) return (1);else (2);}【函数2.2说明】有3个整数,设计函数compare(int a,int b,int c)求其中最大的数。【函数2.2】int compare (int a, int b, int c ){ int temp, max;(3) a:b;(4) temp:c;}【函数2.3说明】递归函数dec(int a[],int n)判断数组a[]的前n个元素是否是不递增的。不递增返回 1,否则返回0。【函数2.3】int dec( int a[], int n ){if(n<=1) return 1;if(a[0]<a[1]) return 0;return (5);}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]已知r[1...n]是n个记录的递增有序表,用折半查找法查找关键字为k的记录。若查找失败,则输出“failure",函数返回值为0;否则输出“success”,函数返回值为该记录的序号值。[C函数]int binary search(struct recordtype r[],int n,keytype k){ intmid,low=1,hig=n;while(low<=hig){mid=(1);if(k<r[mid].key) (2);else if(k==r[mid].key){printf("succesS\n");(3);}else (4);}printf("failure\n");(5);}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。