• 2022-06-05
    执行以下程序后,test.txt文件的内容是(若文件能正常打开) ( )。#include <stdio.h>#include <stdlib.h>main( ) FILE * fp; char * s1 = "Fortran" , * s2 = "Basic"; if((fp = fopen( "test. txt" ," wb" )) = = NULL) prinff( "Can’t open test. txt file \n"); exit(1); fwrite( s1 ,7,1 ,fp); /* 把从地址s1开始到7个字符写到fp所指文件中*/ fseek(fp,OL,SEEK_SET); /*文件位置指针移到文件开头*/ fwrite (s2,5,1,fp); felose (fp);
    A: Basiean
    B: BasieFortran
    C: Basic
    D: FortranBasie
  • A

    举一反三

    内容

    • 0

      假设fp为FILE* 指针变量,如下代码执行后, char *s1="China",*s2="Beijing"; FILE *fp=NULL; fp=fopen("abc.dat","wb"); fwrite(s2,7,1,fp); rewind(fp); fwrite(s1,5,1,fp); fclose(fp);文件abc.dat的内容是 A: Chinang B: China C: ChinaBeijing D: BeijingChina

    • 1

      中国大学MOOC: 假设fp为FILE* 指针变量,如下代码执行后, char *s1=China,*s2=Beijing; fp=fopen(abc.dat,wb); fwrite(s2,7,1,fp); rewind(fp); fwrite(s1,5,1,fp); fclose(fp);文件abc.dat的内容是

    • 2

      以下程序执行后,文件test.txt的内容是() #include void main() { FILE *fp; fp=fopen(“test.txt”,”w”); fprintf(fp,”%s”,”How ”); fclose(fp); fp=fopen(test.txt“,”a”); fprintf(fp,”%s”,”are you!”); fclose(fp); }

    • 3

      向磁盘文件18-1.txt中输入一行字符。 #include "stdio.h" #include "stdlib.h" main() {【1】 *fp; char ch; if((fp=fopen("18-1.txt","w"))==NULL) { printf("Cannot open. "); exit(0); } while((ch=getchar())!=' ') fputc( 【2】 ,fp); 【3】 ; }

    • 4

      有以下程序#include "stdio.h"main(){ FILE *fp; int i, a&#91;6&#93; = {1,2,3,4,5,6}, k; fp = fopen("data.dat", "w+b"); fwrite(&a&#91;0&#93;, sizeof(int), 1, fp); for (i=1; i<6; i++) { fseek(fp, 0L, 0); fwrite(&a[i], sizeof(int), 1, fp); } fseek(fp, 0L, 0); fread(&k, sizeof(int), 1, fp); fclose(fp); printf("%d\n", k);}程序运行后的输出结果是______。[/i] A: 6 B: 21 C: 123456 D: 654321