#include <io.h>
#include <stdio.h>
#include <process.h>
#include <malloc.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys\stat.h>
typedef struct node
{
char szBookName[51]; //책이름
char szAuthor[21]; //저자
char szDay[11]; //발행일
char szPress[11]; //출판사
int iPrice; //가격
struct node* next;
}NODE;
int main()
{
NODE nd;
NODE item;
int infd=0;
int outfd=0;
int not;
//출력 파일 생성
if((outfp=creat("book.out",S_IREAD|S_IWRITE))<0)
{
printf("file create error!");
exit (-1);
}
close (outfd); //파일의 속성을 기록 하기 위해 닫음
//출력 화일을 쓰기 위해 오픈
if((outfp=open("book.out",O_WRONLY|O_TEXT))<0)
{
printf("file open error!\n");
exit(-1);
}
//키보드로 부터 데이터를 입력 받음..
while(1)
{
printf("음수(-)를 입력 하면 종료됨...1..이상이면 계속 입력..");
scanf("%d",¬);
if(not <0)
{
break;
}
printf("책이름을 입력하세요 :");
scanf("%s",item.szBookName);
printf("\n");
printf("책저자를 입력하세요 :");
scanf("%s",item.szAuthor);
printf("\n");
printf("발행일자를 입력하세요 :");
scanf("%s",item.szDay);
printf("\n");
printf("출판사를 입력하세요 :");
scanf("%s",item.szPress);
printf("\n");
printf("가격을 입력하세요 :");
scanf("%s",&item.iPrice);
printf("\n");
write(outfd,&item,sizeof(NODE));
}
close (outfd);
//출력 파일을 읽기 위해서 열기
if((infp=open("book.out",O_RDONLY|O_TEXT))<0)
{
printf("file open error!\n");
exit(-1);
}
while(read(infd,&item,sizeof(NODE))>=sizeof(NODE))
{
printf("\n 책이름 : %s",item.szBookName);
printf("\n 저자 : %s",item.szAuthor);
printf("\n 발행일자: %s",item.szDay);
printf("\n 출판사 : %s",item.szPress);
printf("\n 가격 : %d",item.iPrice);
}
close (infd);
}
'C Source' 카테고리의 다른 글
C언어 문제 (0) | 2010.04.15 |
---|---|
Tipsoft 사이트 (0) | 2010.03.25 |
소수 구하는 프로그램 (0) | 2010.03.25 |
구구단 (3*3) (0) | 2010.03.25 |