Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void) {
- const char *data_file = "shopping.dat";
- int money_in_hand, price;
- char line[BUFSIZ]; /* fgets で使用する行バッファ */
- FILE *in = fopen(data_file, "r");
- if (!in) {
- fprintf(stderr, "open error: %s", data_file);
- exit(1);
- }
- fgets(line, BUFSIZ, in); /* 一行目は所持金 */
- sscanf(line, "%d", &money_in_hand);
- while (fgets(line, BUFSIZ, in)) {
- sscanf(line, "%d", &price);
- money_in_hand -= price;
- if (money_in_hand < 0) {
- puts("足りません。");
- fclose(in);
- exit(1);
- }
- }
- puts("足ります。");
- fclose(in);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement