符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
在show函数中你只是判断了数组元素的大小,根本没有对数组进行操作,所以数组中的元素并没有改变,估计是你写程序时写漏了点东西~~
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名、雅安服务器托管、营销软件、网站建设、定远网站维护、网站推广。
imax=i;
imax=0;
这里的imax=0; 对函数来说是毫无用处的,估计你写漏了~~应该是x[imax]=0才对~
PS: int b 也是没有什么用处的。
即:
#include "stdio.h"
int show (int x[] ,int n)
{
int i,imax;
imax=0;
for (i=1;i=n-1;i++)
if (x[i]x[imax])
imax=i;
x[imax]=0;
return 0;
}
我不是高手。
void in()/*录入学生信息*/
{ int i,m=0;/*m是记录的条数*/
char ch[2];
FILE *fp;/*定义文件指针*/
system("cls");
if((fp=fopen("data.txt","a+"))==NULL)/*打开指定文件*/
{ printf("can not open\n");return;}//要是打开文件失败就直接退出
while(!feof(fp)) { //当文件指针没有指向EOF时继续
if(fread(stu[m] ,LEN,1,fp)==1)从stu中读取LEN个数据,写到fp指向的文件
m++;/*统计当前记录条数*/
}
fclose(fp);//释放文件指针
if(m==0) //如果一个数据都没写入
printf("没有记录!\n");
else
{
system("cls");//清屏
show();/*调用show函数,显示原有信息*/
}
if((fp=fopen("data.txt","wb"))==NULL)//以只写方式创建一个二进制文件,如果原文件存在,清空。如果==NULL,也就是失败,就执行下面的语句。
{ printf("can not open\n");return;}
for(i=0;im;i++) fwrite(stu[i] ,LEN,1,fp);/*向指定的磁盘文件写入信息*/
printf("请输入记录(y/n):");
scanf("%s",ch);
修改以下代码,我以前学习时学编的,相信你的智商!
#includestdio.h
#includestdlib.h
#includeconio.h
#includedos.h
#includestring.h
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"
#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum
float Felec,Fexpe,Frequ;
struct student/*定义学生成绩结构体*/
{
int num;/*学号*/
char name[15];/*姓名*/
double elec;/*选修课*/
double expe;/*实验课*/
double requ;/*必修课*/
double sum;/*总分*/
};
struct student stu[50];/*定义结构体数组*/
void in();/*录入学生成绩信息*/
void show();/*显示学生信息*/
void order();/*按总分排序*/
void del();/*删除学生成绩信息*/
void modify();/*修改学生成绩信息*/
void menu();/*主菜单*/
void insert();/*插入学生信息*/
void total();/*计算总人数*/
void search();/*查找学生信息*/
void main()/*主函数*/
{
int n;
menu();
scanf("%d",n);/*输入选择功能的编号*/
while(n)
{
switch(n)
{
case 1:
in();
break;
case 2:
search();
break;
case 3:
del();
break;
case 4:
modify();
break;
case 5:
insert();
break;
case 6:
order();
break;
case 7:
total();
break;
default:break;
}
getch();
menu();/*执行完功能再次显示菜单界面*/
scanf("%d",n);
}
}
void in()/*录入学生信息*/
{
int i,m=0;/*m是记录的条数*/
char ch[2];
FILE *fp;/*定义文件指针*/
if((fp=fopen("data","ab+"))==NULL)/*打开指定文件*/
{
printf("can not open\n");
return;
}
while(!feof(fp))
{
if(fread(stu[m] ,LEN,1,fp)==1)
m++;/*统计当前记录条数*/
}
fclose(fp);
if(m==0)
printf("No record!\n");
else
{
system("cls");
show();/*调用show函数,显示原有信息*/
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(i=0;im;i++)
fwrite(stu[i] ,LEN,1,fp);/*向指定的磁盘文件写入信息*/
printf("please input(y/n):");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("please input per centum:");
printf("\nelective:");
scanf("%f",Felec);
printf("\nexperiment:");
scanf("%f",Fexpe);
printf("\nrequired course:");
scanf("%f",Frequ);
}
while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要录入新信息*/
{
printf("number:");
scanf("%d",stu[m].num);/*输入学生学号*/
for(i=0;im;i++)
if(stu[i].num==stu[m].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");
scanf("%s",stu[m].name);/*输入学生姓名*/
printf("elective:");
scanf("%lf",stu[m].elec);/*输入选修课成绩*/
printf("experiment:");
scanf("%lf",stu[m].expe);/*输入实验课成绩*/
printf("required course:");
scanf("%lf",stu[m].requ);/*输入必修课成绩*/
stu[m].sum=stu[m].elec*Felec+stu[m].expe*Fexpe+stu[m].requ*Frequ;/*计算出总成绩*/
if(fwrite(stu[m],LEN,1,fp)!=1)/*将新录入的信息写入指定的磁盘文件*/
{
printf("can not save!");
getch();
}
else
{
printf("%s saved!\n",stu[m].name);
m++;
}
printf("continue?(y/n):");/*询问是否继续*/
scanf("%s",ch);
}
fclose(fp);
printf("OK!\n");
}
void show()
{
FILE *fp;
int i,m=0;
fp=fopen("data","ab+");
while(!feof(fp))
{
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf("number name elective experiment required sum\t\n");
for(i=0;im;i++)
{
printf(FORMAT,DATA);/*将信息按指定格式打印*/
}
}
void menu()/*自定义函数实现菜单功能*/
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|---------------------STUDENT-------------------|\n");
printf("\t\t|\t 0. exit |\n");
printf("\t\t|\t 1. input record |\n");
printf("\t\t|\t 2. search record |\n");
printf("\t\t|\t 3. delete record |\n");
printf("\t\t|\t 4. modify record |\n");
printf("\t\t|\t 5. insert record |\n");
printf("\t\t|\t 6. order |\n");
printf("\t\t|\t 7. number |\n");
printf("\t\t|-----------------------------------------------|\n\n");
printf("\t\t\tchoose(0-7):");
}
void order()/*自定义排序函数*/
{
FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open!\n");
return;
}
while(!feof(fp))
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
for(i=0;im-1;i++)
for(j=i+1;jm;j++)/*双重循环实现成绩比较并交换*/
if(stu[i].sumstu[j].sum)
{
t=stu[i];
stu[i]=stu[j];
stu[j]=t;
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(i=0;im;i++)/*将重新排好序的内容重新写入指定的磁盘文件中*/
if(fwrite(stu[i] ,LEN,1,fp)!=1)
{
printf("%s can not save!\n");
getch();
}
fclose(fp);
printf("save successfully\n");
}
void del()/*自定义删除函数*/
{
FILE *fp;
int snum,i,j,m=0;
char ch[2];
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)
break;
if(i==m)
{
printf("can not find");
getchar();
return;
}
printf("find the student,delete?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要进行删除*/
{
for(j=i;jm;j++)
stu[j]=stu[j+1];/*将后一个记录移到前一个记录的位置*/
m--;/*记录的总个数减1*/
printf("delete successfully!\n");
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(j=0;jm;j++)/*将更改后的记录重新写入指定的磁盘文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{
printf("can not save!\n");
getch();
}
fclose(fp);
}
void search()/*自定义查找函数*/
{
FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*查找输入的学号是否在记录中*/
{
printf("find the student,show?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number name elective experiment required sum\t\n");
printf(FORMAT,DATA);/*将查找出的结果按指定格式输出*/
break;
}
else
return;
}
if(i==m)
printf("can not find the student!\n");/*未找到要查找的信息*/
}
void modify()/*自定义修改函数*/
{
FILE *fp;
int i,j,m=0,snum;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("please input the number of the student which do you want to modify!\n");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*检索记录中是否有要修改的信息*/
break;
if(im)
{
printf("find the student!you can modify!\n");
printf("please input per centum:");
printf("\nelective:");
scanf("%f",Felec);
printf("\nexperiment:");
scanf("%f",Fexpe);
printf("\nrequired course:");
scanf("%f",Frequ);
printf("name:\n");
scanf("%s",stu[i].name);/*输入名字*/
printf("\nelective:");
scanf("%lf",stu[i].elec);/*输入选修课成绩*/
printf("\nexperiment:");
scanf("%lf",stu[i].expe);/*输入实验课成绩*/
printf("\nrequired course:");
scanf("%lf",stu[i].requ);/*输入必修课成绩*/
stu[i].sum=stu[i].elec*Felec+stu[i].expe*Fexpe+stu[i].requ*Frequ;
}
else
{
printf("can not find!");
getchar();
return;
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(j=0;jm;j++)/*将新修改的信息写入指定的磁盘文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{
printf("can not save!");
getch();
}
fclose(fp);
}
void insert()/*自定义插入函数*/
{
FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("please input position where do you want to insert!(input the number)\n");
scanf("%d",snum);/*输入要插入的位置*/
for(i=0;im;i++)
if(snum==stu[i].num)
break;
for(j=m-1;ji;j--)
stu[j+1]=stu[j];/*从最后一条记录开始均向后移一位*/
printf("now please input the new information.\n");
printf("number:");
scanf("%d",stu[i+1].num);
for(k=0;km;k++)
if(stu[k].num==stu[i+1].numk!=i+1)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("please input per centum:");
printf("\nelective:");
scanf("%f",Felec);
printf("\nexperiment:");
scanf("%f",Fexpe);
printf("\nrequired course:");
scanf("%f",Frequ);
printf("name:\n");
scanf("%s",stu[i+1].name);
printf("\nelective:");
scanf("%lf",stu[i+1].elec);
printf("\nexperiment:");
scanf("%lf",stu[i+1].expe);
printf("\nrequired course:");
scanf("%lf",stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec*Felec+stu[i+1].expe*Fexpe+stu[i+1].requ*Frequ;
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(k=0;k=m;k++)
if(fwrite(stu[k] ,LEN,1,fp)!=1)/*将修改后的记录写入磁盘文件中*/
{
printf("can not save!");
getch();
}
fclose(fp);
}
void total()
{
FILE *fp;
int m=0;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;/*统计记录个数即学生个数*/
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("the class are %d students!\n",m);/*将统计的个数输出*/
fclose(fp);
}
#includestdio.h
#includestdlib.h
#includeconio.h
#includedos.h
#includestring.h
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"
#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum
struct student/*定义学生成绩结构体*/
{ int num;/*学号*/
char name[15];/*姓名*/
double elec;/*选修课*/
double expe;/*实验课*/
double requ;/*必修课*/
double sum;/*总分*/
};
struct student stu[50];/*定义结构体数组*/
void in();/*录入学生成绩信息*/
void show();/*显示学生信息*/
void order();/*按总分排序*/
void del();/*删除学生成绩信息*/
void modify();/*修改学生成绩信息*/
void menu();/*主菜单*/
void insert();/*插入学生信息*/
void total();/*计算总人数*/
void search();/*查找学生信息*/
void main()/*主函数*/
{ int n;
menu();
scanf("%d",n);/*输入选择功能的编号*/
while(n)
{ switch(n)
{ case 1: in();break;
case 2: search();break;
case 3: del();break;
case 4: modify();break;
case 5: insert();break;
case 6: order();break;
case 7: total();break;
case 8: show();break;
default:break;
}
getch();
menu();/*执行完功能再次显示菜单界面*/
scanf("%d",n);
}
}
void in()/*录入学生信息*/
{ int i,m=0;/*m是记录的条数*/
char ch[2];
FILE *fp;/*定义文件指针*/
if((fp=fopen("data.txt","a+"))==NULL)/*打开指定文件*/
{
printf("can not open\n");
return;
}
while(!feof(fp))
{
if(fread(stu[m] ,LEN,1,fp)==1)
m++;/*统计当前记录条数*/
}
fclose(fp);
if(m==0)
printf("No record!\n");
else
{
system("cls");
show();/*调用show函数,显示原有信息*/
}
if((fp=fopen("data.txt","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(i=0;im;i++)
fwrite(stu[i] ,LEN,1,fp);/*向指定的磁盘文件写入信息*/
printf("please input(y/n):");
scanf("%s",ch);
while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要录入新信息*/
{
printf("number:");
scanf("%d",stu[m].num);/*输入学生学号*/
for(i=0;im;i++)
if(stu[i].num==stu[m].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");
scanf("%s",stu[m].name);/*输入学生姓名*/
printf("elective:");
scanf("%lf",stu[m].elec);/*输入选修课成绩*/
printf("experiment:");
scanf("%lf",stu[m].expe);/*输入实验课成绩*/
printf("required course:");
scanf("%lf",stu[m].requ);/*输入必修课成绩*/
stu[m].sum=stu[m].elec+stu[m].expe+stu[m].requ;/*计算出总成绩*/
if(fwrite(stu[m],LEN,1,fp)!=1)/*将新录入的信息写入指定的磁盘文件*/
{
printf("can not save!");
getch();
}
else
{
printf("%s saved!\n",stu[m].name);
m++;
}
printf("continue?(y/n):");/*询问是否继续*/
scanf("%s",ch);
}
fclose(fp);
printf("OK!\n");
}
void show()
{ FILE *fp;
int i,m=0;
fp=fopen("data.txt","rb");
while(!feof(fp))
{
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf("number name elective experiment required sum\t\n");
for(i=0;im;i++)
{
printf(FORMAT,DATA);/*将信息按指定格式打印*/
}
}
void menu()/*自定义函数实现菜单功能*/
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|---------------------STUDENT-------------------|\n");
printf("\t\t|\t 0. exit |\n");
printf("\t\t|\t 1. input record |\n");
printf("\t\t|\t 2. search record |\n");
printf("\t\t|\t 3. delete record |\n");
printf("\t\t|\t 4. modify record |\n");
printf("\t\t|\t 5. insert record |\n");
printf("\t\t|\t 6. order |\n");
printf("\t\t|\t 7. number |\n");
printf("\t\t|\t 8. show |\n");
printf("\t\t|-----------------------------------------------|\n\n");
printf("\t\t\tchoose(0-8):");
}
void order()/*自定义排序函数*/
{ FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{
printf("can not open!\n");
return;
}
while(!feof(fp))
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
if((fp=fopen("data.txt","wb"))==NULL)
{
printf("can not open\n");
return;}
for(i=0;im-1;i++)
for(j=i+1;jm;j++)/*双重循环实现成绩比较并交换*/
if(stu[i].sumstu[j].sum)
{ t=stu[i];stu[i]=stu[j];stu[j]=t;}
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(i=0;im;i++)/*将重新排好序的内容重新写入指定的磁盘文件中*/
if(fwrite(stu[i] ,LEN,1,fp)!=1)
{
printf("%s can not save!\n");
getch();
}
fclose(fp);
printf("save successfully\n");
}
void del()/*自定义删除函数*/
{FILE *fp;
int snum,i,j,m=0;
char ch[2];
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) if(fread(stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)
break;
printf("find the student,delete?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要进行删除*/
for(j=i;jm;j++)
stu[j]=stu[j+1];/*将后一个记录移到前一个记录的位置*/
m--;/*记录的总个数减1*/
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;jm;j++)/*将更改后的记录重新写入指定的磁盘文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!\n");
getch();}
fclose(fp);
printf("delete successfully!\n");
}
void search()/*自定义查找函数*/
{ FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen("data.txt","rb"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) if(fread(stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0) {printf("no record!\n");return;}
printf("please input the number:");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*查找输入的学号是否在记录中*/
{ printf("find the student,show?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number name elective experiment required sum\t\n");
printf(FORMAT,DATA);/*将查找出的结果按指定格式输出*/
break;
}
}
if(i==m) printf("can not find the student!\n");/*未找到要查找的信息*/
}
void modify()/*自定义修改函数*/
{ FILE *fp;
int i,j,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");
fclose(fp);
return;
}
show();
printf("please input the number of the student which do you want to modify!\n");
printf("modify number:");
scanf("%d",snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*检索记录中是否有要修改的信息*/
break;
printf("find the student!you can modify!\n");
printf("name:");
scanf("%s",stu[i].name);/*输入名字*/
printf("elective:");
scanf("%lf",stu[i].elec);/*输入选修课成绩*/
printf("experiment:");
scanf("%lf",stu[i].expe);/*输入实验课成绩*/
printf("required course:");
scanf("%lf",stu[i].requ);/*输入必修课成绩*/
printf("modify successful!");
stu[i].sum=stu[i].elec+stu[i].expe+stu[i].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;jm;j++)/*将新修改的信息写入指定的磁盘文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!"); getch(); }
fclose(fp);
}
void insert()/*自定义插入函数*/
{ FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");
fclose(fp);
return;
}
printf("please input position where do you want to insert!(input the number)\n");
scanf("%d",snum);/*输入要插入的位置*/
for(i=0;im;i++)
if(snum==stu[i].num)
break;
for(j=m-1;ji;j--)
stu[j+1]=stu[j];/*从最后一条记录开始均向后移一位*/
printf("now please input the new information.\n");
printf("number:");
scanf("%d",stu[i+1].num);
for(k=0;km;k++)
if(stu[k].num==stu[i+1].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");
scanf("%s",stu[i+1].name);
printf("elective:");
scanf("%lf",stu[i+1].elec);
printf("experiment:");
scanf("%lf",stu[i+1].expe);
printf("required course:");
scanf("%lf",stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec+stu[i+1].expe+stu[i+1].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(k=0;k=m;k++)
if(fwrite(stu[k] ,LEN,1,fp)!=1)/*将修改后的记录写入磁盘文件中*/
{ printf("can not save!"); getch(); }
fclose(fp);
}
void total()
{ FILE *fp;
int m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;/*统计记录个数即学生个数*/
if(m==0) {printf("no record!\n");fclose(fp);return;}
printf("the class are %d students!\n",m);/*将统计的个数输出*/
fclose(fp);
}
#includestdio.h
int main()
{ struct stu
{ int id;
char name[11];
int a,b,c;
} t,st[5];
int i,j;
FILE *fp1,*fp2;
if((fp1=fopen("d:\\stud.dat","r"))==NULL)
{ printf("f1 open error!\n");
return 1;
}
if((fp2=fopen("d:\\studsort.dat","w"))==NULL)
{ printf("f2 open error!\n");
return 2;
}
for(i=0; i5; i++)
fscanf(fp1,"%d%s%d%d%d",st[i].id,st[i].name,st[i].a,st[i].b,st[i].c);
for(i=0; i4; i++)
for(j=0; j4-i; j++)
if(st[j].a+st[j].b+st[j].cst[j+1].a+st[j+1].b+st[j+1].c)
{ t=st[j];
st[j]=st[j+1];
st[j+1]=t;
}
for(i=0; i5; i++)
{ printf("%d %10s %4d %4d %4d %7.2f\n",st[i].id,st[i].name,st[i].a,st[i].b,
st[i].c,(st[i].a+st[i].b+st[i].c)/3.0);
fprintf(fp2,"%d %10s %4d %4d %4d %7.2f\n",st[i].id,st[i].name,st[i].a,st[i].b,
st[i].c,(st[i].a+st[i].b+st[i].c)/3.0);
}
fclose(fp1);
fclose(fp2);
return 0;
}
【1】这个是有的,如下示例:printf("%d\n",p-tm_sec); /*获取当前秒*/printf("%d\n",p-tm_min); /*获取当前分*/printf("%d\n",8+p-tm_hour);/*获取当前时,这里获取西方的时间,刚好相差八个小时*/printf("%d\n",p-tm_mday);/*获取当前月份日数,范围是1-31*/printf("%d\n",1+p-tm_mon);/*获取当前月份,范围是0-11,所以要加1*/printf("%d\n",1900+p-tm_year);/*获取当前年份,从1900开始,所以要加1900*/printf("%d\n",p-tm_yday); /*从今年1月1日算起至今的天数,范围为0-365。
【2】c语言:C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点。它由美国贝尔研究所的D.M.Ritchie于1972年推出,1978年后,C语言已先后被移植到大、中、小及微型机上,它可以作为工作系统设计语言,编写系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。它的应用范围广泛,具备很强的数据处理能力,不仅仅是在软件开发上,而且各类科研都需要用到C语言,适于编写系统软件,三维,二维图形和动画,具体应用比如单片机以及嵌入式系统开发。