了解湖南/长沙凯时app资讯,从湖南凯时app网开始!湖南凯时app报名湖南凯时app本科
您当前的位置:凯时app > 湖南凯时app考前练习

凯时app“高级语言程序设计”经典习题及答案(30)

凯时app“高级语言程序设计”经典习题及答案(30)

 

  8.4 程序设计题ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  1.编一个程序,从键盘输入200个字符,存入名为“f1.txt”的磁盘文件中。ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”要将从键盘输入的字符写到指定的文件,程序要定义一个文件指针变量,并以写方式打开指定的文件,然后是一个循环,反复从键盘读人字符,将读人字符复制到文件。程序如下:ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  FILE * fp;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  void main()ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { int i, ch;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if(( fp =fopen(“f1.txt”,“w”))== NULL) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  prinit(“Can‘t open file %s./n”,“f1.txt”); exit(0);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Enter 200 characters. /n”);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for( i = 1;i<=200;i++) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  ch= getchar();ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if( ch== EOF) break;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fputc( ch,fp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fclose(fp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  2.从上一题中建立的名为“f1.txt”的磁盘文件中读取120个字符,并显示在屏幕上。ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”要从指定文件读入字符显示,要以读方式打开,并用循环控制从文件读人字符。程序如下:ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  FILE * fp;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  void main()ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { int i;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if(( fp =fopen(“f1.txt”,“r” ))== NULL) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Can‘t open file %s./n”,“f1.txt” ); exit(0);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=l; i<=120; i++ ) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if(feof(fp)) break;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  putchar( fgetc(fp));ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fclose(fp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“/n”);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  3.编一个程序,将磁盘中的当前目录下名为“ccw1.txt” 的文本文件复制在同一目录下,文件名改为“ccw2.txt”。ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”程序需要两个文件指针变量,一个对应读文件,另一个对应写文件。并分别用读和写方式打开两个文件。ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  接着是以读文件状态作为循环控制条件,在读文件还未结束下循环,反复读人字符,并将读人字符复写到写文件中。程序如下:ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  FILE * rp, * wp;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  void main()ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { int c;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if((rp= fopen(“ccw1.txt”,“r”))== NULL) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Can‘t open file %s./n”,“ccwl.txt”); exit(0);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if((wp= fopen(“ccw2.txt”,“w”))== NULL) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Can‘t open file %s./n”,“ccw2.txt”); exit(0);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  while((c= fgetc(rp))!= EOF)ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fputc( c,wp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fclose(wp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fclose(rp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  4.编程序,对名为“CCW.TXT”的磁盘文件中“@”之前的所有字符加密,加密方法是每个字节的内容减10.ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”程序从文件读出字符,在字符“@”未出现之前,将读出字符作加密处理后回写。加密循环受文件结束或当前字符是“@”字符控制。程序如下:ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # define DALTA 10ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  FILE * rp;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  void main()ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { int c;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if(( rp = fopen(“ccw.txt”,“r+”)) ==NULL ) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Can‘t open file %s./n”,“ccw.txt”); exit(0);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  while(( c= fgetc(rp))!= EOF) {ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if( c ==‘@’) break;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  c+= DALTA;ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fseek( rp,-1L,1 );ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fputc( c, rp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fseek( rp,OL,l);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  fclose(rp);ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

 ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

ZgB湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

 

凯时app“高级语言程序设计”经典习题及答案(30)

    湖南凯时app网——致力于打造湖南凯时app网第一网,以努力服务于广大湖南凯时app学子、提供最全的湖南凯时app资讯为己任,发布湖南凯时app最新的新闻资讯,提供湖南凯时app专科湖南凯时app本科湖南凯时app报名湖南凯时app成绩查询等综合信息

 

湖南凯时app
相关文章
    无相关信息
湖南网站主页
湖南凯时app政策
凯时app30年大事
湖南凯时app专业
湖南凯时app问答
名家访谈
湖南凯时app故事
湖南凯时app院校
湖南凯时app大纲
凯时app复习方法
凯时app笔记串讲
凯时app应试技巧
湖南凯时app真题
湖南凯时app就业
湖南论文指导
湖南凯时app实践
湖南凯时app学位
凯时app成绩查询
凯时app考籍查询
凯时app学历查询


咨询QQ:137847917
13548661633(微信同号)

w66利来国际 w66利来国际 w66利来国际 w66利来国际 w66利来国际