program 6

更新时间:2023-07-19 02:55:07 阅读: 评论:0

Chapter 10 programs :
*******************************************************
#define TRUE    1
#include<stdio.h>appcrash
#include<stdlib.h>
struct personnel{
char name[40];
int agnumb;
double height;
};
struct personnel agent[50];
int n=0;
char numstr[40];
main(){
char ch;
while(TRUE){
printf("\n\'e\' enter new agent \n\'l\'list all agents");歌词
printf("\n\'w\' write file \n\'r\'read file\n\'o\'end the program:"); ch=getchar();getchar();
switch(ch){
ca 'e':newname();break;
ca 'l':listall();break;
ca 'w':wfile();break;
ca 'r':rfile();break;
ca 'o':exit(0);break;
default:puts("\nEnter only lections listed"); }
}
}
newname(){
printf("\nRecord %d \nEnter name:",n+1); gets(agent[n].name);
printf("Enter agent number(3 digit):");
gets(numstr);
agent[n].agnumb=atoi(numstr);
printf("Enter height in cm:");
gets(numstr);
agent[n++].height=atof(numstr);
}
listall(){
int j;
if(n<1)
printf("\nEmpty list.\n");
for(j=0;j<n;j++){
printf("\n Record number %d \n",j+1);
printf("Name:%s\n",agent[j].name);
printf("Agent nmuber:%03d\n",agent[j].agnumb); printf("Height:%4.2f\n",agent[j].height);
油炒面
丹参
}
}
wfile(){
FILE *fptr;
if(n<1){
printf("\nCannot write empty list.\n"); return;
}
if((fptr=fopen("","wb"))==NULL){
printf("\nCanot open \n"); return;
}
el
{
fwrite(agent,sizeof(agent[0]),n,fptr);
fclo(fptr);
printf("\nFile of %d records written.\n",n);
望湖楼醉书
}佛说人生感悟的句子
校运会稿件}
rfile(){
FILE *fptr;
int m=0;
if((fptr=fopen("","rb"))==NULL){
printf("\nCannot open \n");
}
el
{
while((fread(&agent[m],sizeof(agent[m]),1,fptr))==1)
m++;
fclo(fptr);
printf("\nFile read.Total agents is now %d.\n",m+1);
}
}
******************************************************* ******************************************************* #include<stdio.h>
main(){
struct{
char name[40];
int agnumb;
double height;
}agent;
FILE *fptr;
int recno;
long int offt;
if((fptr=fopen("","rb"))==NULL){ printf("Cannot open the \n"); exit(0);
}
printf("Enter record number:");
scanf("%d",&recno);
offt=(recno-1)*sizeof(agent);
if(fek(fptr,offt,0)!=0){
printf("cannot move pointer there.\n");
exit(0);
}
fread(&agent,sizeof(agent),1,fptr);
printf("\nName:%s\n",agent.name);
printf("Number:%03d\n",agent.agnumb); printf("Height:%-2f\n",agent.height);
白居易长恨歌fclo(fptr);
}

本文发布于:2023-07-19 02:55:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1087183.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:感悟   稿件   句子   校运会   人生
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图