외부 데이터에 의해서 출력하는 건데 ..
내꽃
함수에 의해서 돌아가는 프로그램입니다.
워닝 2개만 뜨고 작동은 되는데요
in_data 에 의해 받은 내용을 out_data 로 파일을 바꿔 줘야 하는데
머가 잘못 대었는지 out_data 에는 아무것도 안남네요.
저장되는 폴더에 in_data 넣었는데도 이렇네요..머가 잘못되어서 out_data로 출력이 안되는지 봐주셧음 합니다.
함수 순서는
input_data 입력
caculation 계산
print 출력
입니다
질문 내용 :
#includestdio.h
#includestdlib.h
int Input_data(struct products *others);
int caculation(struct products *others);
int print(struct products *others);
struct products
{
char name[10]; // 품명
int price; // 단가
int volume; // 수량
int prices; // 금액
double discount_price; // 할인액
double real_price; // 지불액
};
FILE *file;
int main(void)
{
struct products others[7];
int i=0 , cnt;
cnt=Input_data(others);
cnt=caculation(others);
cnt=print(others);
return 0;
}
int caculation(struct products *others)
{
int i,cnt;
for(i=0; icnt; i++)
{
others[i].prices = others[i].volume * others[i].price;
if(others[i].volume50)
{
others[i].discount_price = others[i].prices * 0;
}
else if(others[i].volume100)
{
others[i].discount_price = others[i].prices * 0.05;
}
else
{
others[i].discount_price = others[i].prices * 0.1;
}
others[i].real_price = others[i].prices - others[i].discount_price;
}
file = fopen(out_data.txt,wt);
if(file==NULL)
{
printf(The file was not opened \n);
return 0;
}
return 0;
}
int print(struct products *others)
{
int i,cnt;
for(i=0; icnt; i++)
{
fprintf(file, %s \t , others[i].name);
fprintf(file, %d \t , others[i].price);
fprintf(file, %d \t , others[i].volume);
fprintf(file, %d \t , others[i].prices);
fprintf(file, %.lf \t , others[i].discount_price);
fprintf(file, %.lf \n , others[i].real_price);
}
return 0;
}int Input_data(struct products *others)
{
FILE *file;
int i=0,cnt;
file = fopen(in_data.txt , rt);
if(file==NULL)
{
printf(file open error!\n);
exit(1);
}
while(!feof(file))
{
fscanf(file,%s , others[i].name);
fscanf(file,%d , &others[i].price);
fscanf(file,%d , &others[i].volume);
i++;
}
cnt=i;
if(fclose(file)!=0)
{
printf(file close error!\n);
exit(1);
}
*(others+i);
others[i];
return cnt;
}