6.3

#include <stdio.h>
#include<stdlib.h>
struct Student
{
	char Class[10];
	char Num[10];
	char Name[10];
	int score[5];
};
void main()
{
	void menu();
	void input(struct Student stu[],int n);
	void output(struct Student stu[],int n);
	void read_in(struct Student stu[],int n);
	void save(struct Student stu[],int n);
	struct Student stu[40];
	int n=2;
	int choice;
	while(1)
	{
		menu();
		printf("请输入一个选项:");
		scanf("%d",&choice);
		switch(choice) 
		{
		case 1:input(stu,n);break;
		case 2:output(stu,n);break;
		case 3:read_in(stu,n);break;
		case 4:save(stu,n);break;
		case 5:exit(0);
		}
	}
}
void menu()
{
	system("cls");
	printf("\t\t\t1.输入\n");
	printf("\t\t\t2.输出\n");
	printf("\t\t\t3.从文件读入数据\n");
	printf("\t\t\t4.保存至文件\n");
	printf("\t\t\t5.退出\n");
}
void input(struct Student stu[],int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%s%s%s%d%d%d%d%d",stu[i].Class,stu[i].Num,stu[i].Name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3],&stu[i].score[4]);
	} 
}
void output(struct Student stu[],int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		printf("%s %s %s %d %d %d %d %d\n",stu[i].Class,stu[i].Num,stu[i].Name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
	}
	system("pause");
}
void read_in(struct Student stu[],int n)
{
	FILE *fp;
	int i;
	if(fp=fopen("stu.dat","r"==NULL))
	{
		printf("cannot open this file\n");
		exit(0);
	}
	for(i=0;i<n;i++)
	{
		fscanf(fp,"%s%s%s%d%d%d%d%d",stu[i].Class,stu[i].Num,stu[i].Name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3],&stu[i].score[4]);
	} 
	fclose(fp);
}
void save(struct Student stu[],int n)
{
	FILE *fp;
	int i;
	if((fp=fopen("stu.dat","w"))==NULL)
	{ 
		printf("cannot open this file\n"); 
		exit(0); 
	}
	for(i=0;i<n;i++)
	{
		fprintf(fp,"%s %s %s %d %d %d %d %d\n",stu[i].Class,stu[i].Num,stu[i].Name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
	}
	fclose(fp);
}

有一个磁盘文件,第一次将它的内容显示在屏幕上,第二次把它复制到另一文件上

#include <stdio.h>
#include<stdlib.h>
void main()
{
	FILE *fp1,*fp2;
	fp1=fopen("stu.dat","r");
	fp2=fopen("txet.txt","w");
	while(!feof(fp1))
	{
		putchar(fgetc(fp1));
	}
	rewind(fp1);
	while(!feof(fp1)) 
	{
		fputc(fgetc(fp1),fp2);
	}
	fclose(fp1);
	fclose(fp2);
}

有10个包括姓名及电话号码的数据,编写程序将其存储到文件中。分别存储为ASCII(即fprintf、fscanf)与二进制(即fread、fwrite)两种形式。

ASCII

#include <stdio.h>
#include<stdlib.h>
//有10个包括姓名及电话号码的数据,编写程序将其存储到文件中,分别存储为ASCII(即fprintf、fscanf)形式
struct Telephone
{
	char Name[10];
	long int Tele_Num;
};
void main()
{
	void read_in(struct Telephone Tele[],int n);
	void save(struct Telephone Tele[],int n);
	struct Telephone Tele[10];
	int i,n=3;
	for(i=0;i<n;i++)
	{
		scanf("%s%ld",Tele[i].Name,&Tele[i].Tele_Num);
	} 
	save(Tele,n);
	read_in(Tele,n);
}
void read_in(struct Telephone Tele[],int n) 
{
	FILE *fp;
	int i=0;
	if((fp=fopen("Text.txt","r"))==NULL)
	{ 
		printf("cannot open this file\n"); 
		exit(0); 
	}
	for(i=0;i<n;i++)
	{
		fscanf(fp,"%s%ld\n",&Tele[i].Name,&Tele[i].Tele_Num);
	}
	fclose(fp); 
}
void save(struct Telephone Tele[],int n) 
{
	FILE *fp;
	int i;
	if((fp=fopen("Text.txt","w"))==NULL)
	{ 
		printf("cannot open this file\n"); 
		exit(0);
	}
	for(i=0;i<n;i++)
	{
		fprintf(fp,"%s%ld\n",Tele[i].Name,Tele[i].Tele_Num);
	}
	fclose(fp);
}

二进制

#include <stdio.h>
#include<stdlib.h>
//有10个包括姓名及电话号码的数据,编写程序将其存储到文件中,分别存储为二进制(即fread、fwrite)形式
struct Telephone
{
	char Name[10];
	long int Tele_Num;
};
void main()
{
	void read_in(struct Telephone Tele[],int n);
	void save(struct Telephone Tele[],int n);
	struct Telephone Tele[10];
	int i,n=3;
	printf("输入储存的数据:\n");
	for(i=0;i<n;i++)
	{
		scanf("%s%ld",Tele[i].Name,&Tele[i].Tele_Num);
	}
	save(Tele,n);
	read_in(Tele,n);
	printf("输出储存的数据:\n");
	for(i=0;i<n;i++)
	{
		printf("%s%ld\n",Tele[i].Name,&Tele[i].Tele_Num);
	}
}
void read_in(struct Telephone Tele[],int n) 
{ 
	FILE *fp;
	int i=0;
	if((fp=fopen("stu.dat","r"))==NULL)
	{ 
		printf("cannot open this file\n"); 
		exit(0);
	}
	for(i=0;i<n;i++)
	{
		fread(&Tele[i],sizeof(struct Telephone),1,fp);
	}
	fclose(fp); 
}
void save(struct Telephone Tele[],int n) 
{
	FILE *fp;
	int i;
	if((fp=fopen("stu.dat","w"))==NULL)
	{ 
		printf("cannot open this file\n"); 
		exit(0);
	}
	for(i=0;i<n;i++)
	{
		fwrite(&Tele[i],sizeof(struct Telephone),1,fp);
	}
	fclose(fp);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
vdhcoapp6.3是指一个软件或应用程序的版本号。根据版本号中的数字,我们可以推断这是该软件或应用程序的第六个版本的第三个分支或更新。版本号的每个部分都有特定的含义,它们被用来表示软件的更新和改进。通常,当开发者对软件进行了一些改动或增加新功能时,他们会发布新的版本。在该版本号中,"vdhcoapp"可能是软件或应用程序的名称的缩写,而"6.3"则代表了具体的版本号。 由于没有具体提及软件或应用程序的名称和功能,所以很难对vdhcoapp6.3进行具体的解释。但是,一般而言,软件的更新版本通常会包括对先前版本中的错误和漏洞进行修复,改进用户界面和性能,增加新的功能和功能改进等。可以推测,在vdhcoapp6.3中,开发者可能对先前版本中的一些问题进行了修复,并可能引入了一些新的功能或改进了现有的功能。 对于具体的功能和特性,我们需要查阅软件或应用程序的相关文档或开发者的说明。通过了解软件或应用程序的名称和用途,我们可以更加详细地了解vdhcoapp6.3的具体含义和作用。 总之,vdhcoapp6.3是一个软件或应用程序的版本号,代表该软件或应用程序的第六个版本的第三个分支或更新。根据版本号,我们可以推测该版本可能包括了对先前版本中的问题进行修复,以及新的功能或改进的引入。为了更深入地了解其功能和特性,需要查阅详细的相关文档或开发者的说明。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值