以下程序运行后,文件test.txt的内容是( )。 #include <stdio.h> main() { FILE *fp; char str[][10]={"first","second"}; fp = fopen("test.txt", "w"); if(fp!=NULL) fprintf(fp,"%s",str[0]); fclose(fp); fp = fopen("test.txt", "w"); if(fp!=NULL) fprintf(fp,"%s",str[1]); fclose(fp); }
下面程序的运行结果是( )。 #include <stdio.h> main() { FILE *fp; int a=2,b=4,c=6,k,n; fp=fopen("test.dat","w"); fprintf(fp,"%d\n",a); fprintf(fp,"%d %d\n",b,c); fclose(fp); fp=fopen("test.dat","r"); fscanf(fp,"%d%*d%d",&k,&n); printf("%d %d\n",k,n); fclose(fp); }
对下面程序描述错误的是( )。 #include <stdio.h> main() { int c; FILE *fp; if((fp=fopen("file.dat","rb+"))!=NULL) { c=fgetc(fp); c=c+1;} fseek(fp,0,SEEK_SET); fputc(i,fp); fclose(fp); }
文本文件quiz.txt的内容为"Programming" (不包含引号),以下程序段的运行结果是( )。 FILE *fp; char *str; if((fp=fopen("quiz.txt","r"))!=NULL) str=fgets(str,7,fp); printf("%s",str);
对下面程序描述正确的是( )。 #include <stdio.h> #include <stdlib.h> void main() {FILE *in,*out; if((in=fopen("file1.txt","a+"))==NULL) {printf("cannot open file1\n"); exit(0); } if((out=fopen("file2.txt","a+"))==NULL) {printf("cannot open file2\n"); exit(0); } while(!feof(out)) fputc(fgetc(out),in); fclose(in); fclose(out); }
对下面程序描述错误的是( )。 #include <stdio.h> main() { int c; FILE *fp; if((fp=fopen("file.dat","rb+"))!=NULL) { c=fgetc(fp); c=c+1;} fseek(fp,0,SEEK_SET); fputc(i,fp); fclose(fp); }
对于以下程序,说法正确的是( )。 #include <stdio.h> main() { FILE *fp; fp=fopen("quiz.txt", "w"); if(fp!=NULL) { fprintf(fp,"%s\n", "success!"); fclose(fp); printf("ok!"); } }
对下面程序描述正确的是( )。 #include <stdio.h> #include <stdlib.h> void main() {FILE *in,*out; if((in=fopen("file1.txt","a+"))==NULL) {printf("cannot open file1\n"); exit(0); } if((out=fopen("file2.txt","a+"))==NULL) {printf("cannot open file2\n"); exit(0); } while(!feof(out)) fputc(fgetc(out),in); fclose(in); fclose(out); }