#include<stdio.h>
#include<stdlib.h>
#define FILENAME "book-6.dat"
struct BOOK{
char date[50];
char item[100];
int flag;
int tanka;
int suryo;
};
#if 0
20120601 1 meat 125 10000
20120602 1 rice 2000 10
20120603 0 uriage 500 100
20120603 1 beer 140 24
#endif
#define MAXLINE 100
int readData(FILE *fp, struct BOOK *book) {
int i;
for (i = 0; i < MAXLINE; i++) {
if (fscanf(fp
, "%s %d %s %d %d\n", book[i].date, &book[i].flag, book[i].item, &book[i].tanka, &book[i].suryo) != 5)
break;
}
return i;
}
int main() {
struct BOOK mybook[100];
int i, n;
FILE *fp;
if((fp
= fopen(FILENAME
, "r")) == 0) { fprintf(stderr
, "%s cannot be found!\n", FILENAME
); }
n = readData(fp, mybook);
for(i = 0; i < n; i++){
printf("%s : %d x %d\n", mybook
[i
].
item, mybook
[i
].
tanka, mybook
[i
].
suryo); }
return 0;
}
/* end */
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CgojZGVmaW5lIEZJTEVOQU1FICJib29rLTYuZGF0IgpzdHJ1Y3QgQk9PS3sKICBjaGFyIGRhdGVbNTBdOwogIGNoYXIgaXRlbVsxMDBdOwogIGludCBmbGFnOwogIGludCB0YW5rYTsKICBpbnQgc3VyeW87Cn07CgojaWYgMAoyMDEyMDYwMSAxIG1lYXQgICAgMTI1IDEwMDAwCjIwMTIwNjAyIDEgcmljZSAgIDIwMDAgICAgMTAKMjAxMjA2MDMgMCB1cmlhZ2UgIDUwMCAgIDEwMAoyMDEyMDYwMyAxIGJlZXIgICAgMTQwICAgIDI0CiNlbmRpZgoKI2RlZmluZSBNQVhMSU5FIDEwMAoKaW50IHJlYWREYXRhKEZJTEUgKmZwLCBzdHJ1Y3QgQk9PSyAqYm9vaykgewogIGludCBpOwogIGZvciAoaSA9IDA7IGkgPCBNQVhMSU5FOyBpKyspIHsKICAgIGlmIChmc2NhbmYoZnAsICIlcyAlZCAlcyAlZCAlZFxuIiwKICAgICAgICAgICAgICAg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