《C语言程序设计》实验指导书答案

FILE *fp;

if((fp=fopen(\ {

printf(\ exit(0); }

for(i=0;i

fwrite(&s[i],sizeof(struct student),1,fp);//写入文件后看是乱码 fclose(fp);*/

FILE *fp1;//把写入文件的数据再次读出来 if((fp1=fopen(\ {

printf(\ exit(0); }

for(i=0;i

fread(&s[i],sizeof(struct student),1,fp1); for(i=0;i

printf(\ fclose(fp1);

system(\}

3. //用定义结构类型的方法,编写程序建立一个具有学生学号、姓名、总分和联系电话的记录文件。

#include #include #define m 10 struct student{ long no;

char name[10]; int score;

long telephone; };

main() {

int i,n;

struct student s[m]; printf(\ scanf(\ for(i=0;i

printf(\ scanf(\

printf(\ scanf(\

printf(\ scanf(\ printf(\ scanf(\ }

for(i=0;i

printf(\ FILE *fp;

if((fp=fopen(\ {

printf(\ exit(0); }

for(i=0;i

fwrite(&s[i],sizeof(struct student),1,fp);//写入文件后看是乱码 fclose(fp);

system(\}

4. //编写程序,利用第3题建立的记录文件,从键盘上输入一个学号,可以查寻到此人其他信息。

#include #include #define m 10 struct student{ long no;

char name[10]; int score;

long telephone; };

main() {

int i,n;

struct student s[m]; printf(\ scanf(\/* for(i=0;i

printf(\ scanf(\ printf(\

scanf(\ printf(\ scanf(\

printf(\ scanf(\ }

for(i=0;i

printf(\ FILE *fp;

if((fp=fopen(\ {

printf(\ exit(0); }

for(i=0;i

fwrite(&s[i],sizeof(struct student),1,fp);//写入文件后看是乱码 fclose(fp);*/

FILE *fp1;//把写入文件的数据再次读出来 if((fp1=fopen(\ {

printf(\ exit(0); }

for(i=0;i

fread(&s[i],sizeof(struct student),1,fp1); int no;

printf(\ scanf(\ for(i=0;i

if(s[i].no==no)

printf(\ }

fclose(fp1);

system(\}

5. //编写程序,将第四题建立的文件复制一份。 #include #include #define m 10 struct student{ long no;

char name[10]; int score;

long telephone; };

main() {

int i,n;

struct student s[m]; printf(\ scanf(\/* for(i=0;i

printf(\ scanf(\ printf(\ scanf(\ printf(\ scanf(\

printf(\ scanf(\ }

for(i=0;i

printf(\ FILE *fp;//用于复制文件,即从原始文件中读出后再写入fp if((fp=fopen(\ {

printf(\ exit(0); }

// for(i=0;i

// fwrite(&s[i],sizeof(struct student),1,fp);//写入文件后看是乱码

FILE *fp1;//用于读出record.txt 文件。 if((fp1=fopen(\ {

printf(\ exit(0); }

for(i=0;i

{ fread(&s[i],sizeof(struct student),1,fp1); fwrite(&s[i],sizeof(struct student),1,fp); }

联系客服:779662525#qq.com(#替换为@)