1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
void io_operator_binary() {
FILE *fd = fopen("sys", "wb"); for(int i = 0; i < 10; ++ i) { Sys_Info t = {i, i * 10, "this is test", "2016-10-06"}; fwrite(&t, sizeof(Sys_Info), 1, fd); } fclose(fd);
fd = fopen("sys", "rb"); Sys_Info tmp[10]; for(int i = 0; i < 10; ++ i) { fread(&tmp[i], sizeof(Sys_Info), 1, fd); }
fseek(fd, 5 * sizeof(Sys_Info), SEEK_SET); Sys_Info sys_info; fread(&sys_info, sizeof(Sys_Info), 1, fd); fclose(fd); }
void io_operator_ascii() { FILE *fd = fopen("sys", "w"); for(int i = 0; i < 10; ++ i) { Sys_Info t = {i, i * 10, "this-is-test", "2016-10-06"};
fprintf(fd, "%d %d %s %s ", t.vesion, t.sub_version, t.info, t.date); } fclose(fd);
fd = fopen("sys", "r"); Sys_Info tmp[10]; for(int i = 0; i < 10; ++ i) {
fscanf(fd, "%d%d%s%s", &tmp[i].vesion, &tmp[i].sub_version, tmp[i].info, tmp[i].date); } fclose(fd); }
|