Some Problem With My Program
Problem: I created a program for booking tickets. It works fine when its for single user. But when i make it for multi user, "user[100]". Funny characters starts to pop up when i key in the seats numbers. Example Smiling face, heart shape etc. When i open the source file user.txt those funny characters is printed as C in the file. Causing my program to be very unstable. Below is my code for booking.
-
Code:
int choice();
int i,m,n,row,column,x=5,y=5;
#define FILENAME "user.txt"
void show_main_menu();
void logo();
void book_ticket();
void edit_booking();
void cancel_booking();
void view_available();
void exitt();
void thank_you();
void look_up();
struct data
{
char useless[1];
char seat[5][10];
char name[30];
char nirc_number[10];
char contact_number[10];
}user[100], data, sales_data[100], temp;
Code:
/*#############################################################################*/
/* Book Ticket Function */
/*#############################################################################*/
void book_ticket()
{
FILE *fptr;
int quit=1;
textcolor(YELLOW);
fptr=fopen("user.txt","r");
fread(&user[100],sizeof(user[100]),1,fptr);
fclose(fptr);
while(column!=99)
{
system("cls");
user[100].seat[row-1][column-1]='X';
printf("\t\t\t \t SCREEN \n\n");
printf("\t\t 1 2 3 4 5 6 7 8 9 10\n");
printf("\n\t\t\t1 ");
for(i=0;i<10;i++)
{
if(user[100].seat[0][i]>0)
printf(" %c ",user[100].seat[0][i]);
}
printf("\n\n");
printf("\t\t\t2 ");
for(i=0;i<10;i++)
{if(user[100].seat[0][i]>0)
printf(" %c ",user[100].seat[1][i]);
}
printf("\n\n");
printf("\t\t\t3 ");
for(i=0;i<10;i++)
{if(user[100].seat[0][i]>0)
printf(" %c ",user[100].seat[2][i]);
}
printf("\n\n");
printf("\t\t\t4 ");
for(i=0;i<10;i++)
{if(user[100].seat[0][i]>0)
printf(" %c ",user[100].seat[3][i]);
}
printf("\n\n");
printf("\t\t\t5 ");
for(i=0;i<10;i++)
{if(user[100].seat[0][i]>0)
printf(" %c ",user[100].seat[4][i]);
}
printf("\n\n\n\n\n");
printf("\t\t\t Enter Row Column(99,99 to quit): "); //choose to for 'X'
scanf("%d,%d",&row, &column);
if(row==99)
break;
}
clrscr();
logo();
printf("\n\n\n\n\t");
gets(user[100].useless);
printf("\n\tPlease Enter Your Name:");
gets(user[100].name);
printf("\n\tPlease Enter Owner IC Number:");
gets(user[100].nirc_number);
printf("\n\tPlease Enter Your Contact Number:");
gets(user[100].contact_number);
fopen("user.txt", "ab+");
fwrite(&user[100],sizeof(user[100]),1,fptr);
fclose(fptr);
printf("\n\n\n\n");
printf("\n\tThank You For Providing Your Details");
printf("\n\tPress Anykey To Continue");
getch();
thank_you();
}
-
If i was to change the "user[100]" to "user" it works fine. But i need it to be multi users. I have totally no idea how i can solve this problem. Appreciate help from members in this forum.
Can upload my whole program too if necessary. Heres the screenshot.
http://www.geocities.com/eradicate85/Program.JPG