외부 데이터에 의해서 출력하는 건데 ..
내꽃
함수에 의해서 돌아가는 프로그램입니다.
워닝 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;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |