programmirovanie / Лек_2_2_файлы / прим_3_ф_пр
.doc/* F_PRM_7.c */
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
/*-----------------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------------*/
/*void File_input();
void File_output();*/
struct RECORD
{ char name[15];
int s1,s2,col1,col2;
}a;
FILE*fv;
FILE*fp;
int N=0;
/*-----------------------------------------------------------------------*/
main()
{void File_input();
void File_output();
clrscr();
File_input();
printf("\n введены исх.данные\n");
File_output();
printf("\n результат есть");
getch();
}
/*-----------------------------------------------------------------------*/
void File_input()
{ char t1,t2,t3,t4;
int i;
if((fv=fopen("10.txt","w"))==NULL)
{ printf("ЋиЁЎЄ ®вЄалвЁп д ©« \n");
exit(-1);
};
strcpy(a.name,"a");
/* while(strcmp(a.name,"")!=0)*/
for(i=1;i<3;i++)
{ printf("Наимнование культуры:");
scanf("%s",a.name);
printf("пос. Площ. 1954 Ј:");
scanf("%d",&a.s1);
printf("пос. Площ1957 Ј:");
scanf("%d",&a.s2);
printf("‘Сбор урожая 1954 Ј:");
scanf("%d",&a.col1);
printf("‘Сбор урожая 1957 Ј:");
scanf("%d",&a.col2);
fwrite(&a,sizeof(a),1,fv);
}
printf(" Все данные записаны в файл 10.txt\n");
fclose(fv);
getch();
}
void File_output()
{ int uk,i;
fp=fopen("10.txt","r");
fseek(fp,0,SEEK_END);
uk=ftell(fp);
printf("uk=%d\n",uk);
i=0;
while(i<uk)
{ fseek(fp,i,SEEK_SET);
fread(&a,sizeof(a),1,fp);
fseek(fp,ftell(fp),SEEK_SET);
printf("\n%s%d%d%d%d",a.name,a.s1,a.s2,a.col1,a.col2);
printf("\n%s%d%d%d%d",a.name,a.s1,a.s2,a.col1,a.col2);
i+=sizeof(a);
}
i=sizeof(a);
i=0;
fseek(fp,i,SEEK_SET);
fread(&a,sizeof(a),1,fp);
printf("\n %s %d %d %d %d ",a.name,a.s1,a.s2,a.col1,a.col2);
fclose(fp);
printf("xxxx");
getch();
}