게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
구조체 동적할당 하다 뭐가 문제인지 몰라서 질문 올려요...
게시물ID : freeboard_339154짧은주소 복사하기
작성자 : 효밍
추천 : 0
조회수 : 247회
댓글수 : 0개
등록시간 : 2009/05/06 23:18:41
#include "fstream.h"
#include <string.h>

typedef struct {
char names[20];
int types;
char codes[20];
int prices[2];
} test;
test* list[20];

void input(test* wp, ifstream& in);
void print(test* wp);

char* Categories[4] = {"건강용품", "화장품__", "침구____", "의류잡화"};

void main(int argc, char* argv[])
{
int count=0;
ifstream in("test2a.txt");
while (!in.eof()) {
list[count] = new test;
input(list[count], in);
count++;
}

for (int i = 0; i < count; i++)
print(list[i]);
}

void input(test* wp, ifstream& in)
{
wp = new test; 
in >> wp->types >> wp->names >> wp->codes >> wp->prices[0] >> wp->prices[1];
}

void print(test* wp)
{
cout << Categories[wp->types-1] << ' ' << wp->names << "\t" << wp->codes
<< '\t' << wp->prices[0] << "원 (" << wp->prices[1] << ", " 
<< (wp->prices[1]-wp->prices[0])*100 /wp->prices[1] << "% 할인)\n";
}

지금까지 짠 코드는 이건데... 뭐가 잘못되었는지 잘 모르겠네요;;;

아마 저기 프린트함수에서 문제가 생긴거같은데... 뭐가 문제인지 잘...
꼬릿말 보기
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호