#include <stdio.h>
#define base_size 50
struct writer {
char *lastname;
char *id;
char *bookname;
int yearofedition;
};
int main() {
FILE *p_file, *e_file;
unsigned short int n_in;
writer *e_avtor, *t_avtor;
p_file = fopen("P.dat", "wb");
e_avtor->lastname="Shevchenko"; e_avtor->id="T.G."; e_avtor->bookname="Kobzar"; e_avtor->yearofedition=1830;
n_in = fwrite(e_avtor, sizeof(*e_avtor), 1, p_file);
e_avtor->lastname="Tolstoj"; e_avtor->id="I.V."; e_avtor->bookname="War and Peace"; e_avtor->yearofedition=1879;
n_in = fwrite(e_avtor, sizeof(*e_avtor), 1, p_file);
e_avtor->lastname="Perymov"; e_avtor->id="A.B."; e_avtor->bookname="Matrx"; e_avtor->yearofedition=1930;
n_in = fwrite(e_avtor, sizeof(*e_avtor), 1, p_file);
fclose(p_file);
if((p_file = fopen("P.dat","rb")) == NULL) {
fprintf(stderr,"Can not open file\n");
return 1;
}
int number_of_record = 0;
writer *w_temp[base_size];
printf("%c",'\n');
while(!feof(p_file)) {
if ( fread(w_temp[number_of_record], sizeof(*w_temp), 1, p_file) /*== sizeof(*w_temp)*/ ) { // <- вот здесь
printf("%s\n", w_temp[number_of_record]->lastname);
++number_of_record;
}
}//printf();
//for(int i=0;i<base_size;i++)
return 0;
}
Си файли, неправельный вывод на экран |