c언어 파일처리 질문드립니다

aoxks00의 이미지

파일처리부분이 미흡한데 이렇게 해보았더니 이름부분만 제대로 들어가고 나머지부분은 이상한언어로만 들어가네요 ㅠㅠ

#include
#include
#include
#include
#include
#define MAXROW 11
#define MAXCOL 9
int reservation(); // 예매
void menu1();
typedef struct reser_infor {
char name[20]; //이름
int number; //예매번호
int phonnumber; //휴대폰번호
int ga; //가로좌석번호
int se; //세로좌석번호
} RESER_INFOR;
int file_exist1; //파일 생성 체크
void gotoxy(int x, int y)
{
COORD Pos = { x,y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void print(int seat[MAXROW][MAXCOL])
{
int i, j, n;
puts("");
printf(" ");
for (i = 0; i < MAXCOL; i++) {
printf("%3d", i + 1);
}
puts("");
printf(" ");
for (i = 0; i < MAXCOL; i++) {
printf("---");
}
puts("");
n = 0;
for (i = 0; i < MAXROW; i++) {
printf("%3d:", i + 1);
for (j = 0; j < MAXCOL; j++)
{
if (seat[i][j]) {
printf("■ ");
}
else {
printf("□ ");
n++;
}
}
puts("");
}
puts("\n");
printf("현재남은자리 = %d\n\n", n);
}
int main()
{
RESER_INFOR a;
FILE *fp1=NULL;
fp1= fopen("game1.txt","r");
int cnt;
if(fp1==NULL){ // 파일이 존재하지 않았을때 실행된다.
file_exist1=0; //기존 파일이 존재하지 않으면 file_exist에 0(zero) 입력
}
else{
file_exist1=1; //파일이 존재할때
fclose(fp1); //파일이 존재할때 반드시 닫아준다.
}
menu1();
return 0;
}
void menu1()
{
int choice;
char temp[20];
while (1)
{
system("cls");
printf("\n\n\n\n\t\t┌──────────────────┐\n");
printf("\t\t│ 예매관리 메 뉴 │\n");
printf("\t\t├──────────────────┤\n");
printf("\t\t│ │\n");
printf("\t\t│ 1. 예 매 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 2. 예매확인 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 3. 예매취소 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 4. 좌석변경 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 5. 음식주문 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 6. 종 료 │\n");
printf("\t\t│ │\n");
printf("\t\t└──────────────────┘\n");

printf("\n\t\t┌───────────────────┐\n");
printf("\t\tㅣ S E L E C T : ㅣ\n");
printf("\t\t└───────────────────┘\n");
gotoxy(36, 23);
gets(temp);
choice = atoi(temp);

if (choice == 1)
reservation();
else if (choice == 2)
reservationdata();
else if (choice == 3)
reservationrevoke();
else if (choice == 4)
seatchange();
else if (choice == 5)
orderoffood();
else if (choice == 6)
break;
else
{
printf("\n\t\t메뉴에있는 번호를 선택하지 않으셨으므로 종료하겠습니다.\n\n\n");
exit(1);
}
}
}
int reservation()
{
RESER_INFOR a;
char temp[50];
int choice;
int seat[MAXROW][MAXCOL];
int i, j;
int print_flag;
int cho;
FILE *fp1=NULL;
srand((unsigned)time(NULL));
for (i = 0; i < MAXROW; i++) {
for (j = 0; j < MAXCOL; j++) {
seat[i][j] = rand() & 1;
}
}
while (1)
{
system("cls");
printf("\n\n\n\n\t\t┌──────────────────┐\n");
printf("\t\t│ 경기를 선택하세요 │\n");
printf("\t\t├──────────────────┤\n");
printf("\t\t│ │\n");
printf("\t\t│ 1. KIA : NC │\n");
printf("\t\t│ │\n");
printf("\t\t│ 2. 두산 : SK │\n");
printf("\t\t│ │\n");
printf("\t\t│ 3. LG : 넥센 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 4. 롯데 : 한화 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 5. KT : 삼성 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 6. 종 료 │\n");
printf("\t\t│ │\n");
printf("\t\t└──────────────────┘\n");

printf("\n\t\t┌───────────────────┐\n");
printf("\t\tㅣ S E L E C T : ㅣ\n");
printf("\t\t└───────────────────┘\n");
gotoxy(36, 23);
gets(temp);
choice = atoi(temp);

if (choice == 1){
if(file_exist1==1){ //파일이 있다
fp1=fopen("game1.txt","a"); //파일이 있을경우 추가모드로 열어줍니다.
if(fp1==NULL){
printf("파일을 열 수 없습니다.\n");
}
}
else{//파일이 없을경우
fp1=fopen("game1.txt","w"); //파일이 없을경우 쓰기모드 열어줍니다.
if(fp1==NULL){
printf("파일을 열 수 없습니다.\n");
}
}
file_exist1=1;
system("cls");
printf("\t\t────────────────────\n");
printf("\t\t이름:");
gets(a.name);
printf("\t\t휴대폰번호:");
gets(temp);
a.phonnumber=atoi(temp);
fprintf(fp1,"%d",a.phonnumber);
while (1) {
if (print_flag)
print(seat);
puts("\n 가로줄과 세로칸을 선택하세요\n");
printf(" 가로줄(1~%d):", MAXCOL);
scanf_s("%d", &i);
fprintf(fp1,"%d",a.ga);

if (i <= 0) {
break;
}
else if (i > MAXCOL) {
printf("\n %d줄을 넘는 자리는 존재하지않습니다 다시 입력하세요\n");
print_flag = 0;
continue;
}
printf("세로줄(1~%d):", MAXROW);
scanf_s("%d", &j);
fprintf(fp1,"%d",a.se);
if (j <= 0) {
break;
}
else if (j > MAXROW) {
printf("\n %d줄을 넘는 자리는 존재하지않습니다 다시 입력하세요\n");
print_flag = 0;
continue;
}
if (seat[i - 1][j - 1] == 0) {
seat[i - 1][j - 1] = 1;
printf("\n %d줄 %d칸 좌석이 예약되었습니다\n\n", i, j);
printf("예매를 종료합니다");
a.number=rand()%1000+1;
fprintf(fp1,"%d ",a.number);
Sleep(3000);
break;
}
else {
printf("\n %d줄 %d칸은 이미 예약되어있습니다\n\n", i, j);
print_flag = 0;
continue;
}
}
else if (choice == 6){
break;
}
else
{
printf("\n\t\t메뉴에있는 번호를 선택하지 않으셨으므로 종료하겠습니다.\n\n\n");
exit(1);
}
system("cls");
print_flag = 1;
}
}

세벌의 이미지

소스코드는 code 태그 안에 넣어서 질문하세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.