/*
\\次のような家計簿データkakeibo.datがテキストでかかれてあり、中身を見ると
\\meat 125 1
\\rice 2000 1
\\juice 110 10
\\となっているものとする。このうち右端は商品名、真ん中は単価、左端は数量を表して
\\いる。このようなデータを読み取って使用金額の合計を計算するプログラミングを作り
\\たい。以下のプログラムをコンパイルがとおり、目的の動作をするように直接書き込み
\\なさい。(どこを補うべきかも考えること)ただし商品名は空欄を含まない文字列とする。
*/
#include<stdio.h>
#include<stdlib.h>
#define FILENAME "kakeibo.dat"
int goukei(FILE *fp);
int main(){
FILE *fp;
fp
= fopen(FILENAME
,"r"); if(fp==NULL){
fprintf(stderr
,"%s is not found!\n",FILENAME
); }
printf("goukei = %d\n",goukei
(fp
)); return 0;
}
int goukei(FILE *fp){
int sum =0, tanka, suryou;
char str[50];
while (fscanf("%s %d %d", str
, &tanka
, &suryou
)!=EOF
){ sum += tanka * suryou;
}
return sum;
}
LyoKXFzmrKHjga7jgojjgYbjgarlrrboqIjnsL/jg4fjg7zjgr9rYWtlaWJvLmRhdOOBjOODhuOCreOCueODiOOBp+OBi+OBi+OCjOOBpuOBguOCiuOAgeS4rei6q+OCkuimi+OCi+OBqApcXG1lYXQgMTI1IDEKXFxyaWNlIDIwMDAgMQpcXGp1aWNlIDExMCAxMApcXOOBqOOBquOBo+OBpuOBhOOCi+OCguOBruOBqOOBmeOCi+OAguOBk+OBruOBhuOBoeWPs+err+OBr+WVhuWTgeWQjeOAgeecn+OCk+S4reOBr+WNmOS+oeOAgeW3puerr+OBr+aVsOmHj+OCkuihqOOBl+OBpgpcXOOBhOOCi+OAguOBk+OBruOCiOOBhuOBquODh+ODvOOCv+OCkuiqreOBv+WPluOBo+OBpuS9v+eUqOmHkemhjeOBruWQiOioiOOCkuioiOeul+OBmeOCi+ODl+ODreOCsOODqeODn+ODs+OCsOOCkuS9nOOCigpcXOOBn+OBhOOAguS7peS4i+OBruODl+ODreOCsOODqeODoOOCkuOCs+ODs+ODkeOCpOODq+OBjOOBqOOBiuOCiuOAg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