HELP with Structure Problem in C!

Page 1 of 1

3 Replies - 1143 Views - Last Post: 07 March 2009 - 12:08 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=91141&amp;s=3040dda11b1ee4928ecdd3f00079ed4b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 philboy

Reputation: 0
• Posts: 2
• Joined: 06-March 09

HELP with Structure Problem in C!

Posted 06 March 2009 - 11:22 PM

Hi to all. Problem: Make an airline reservation program in C. The passenger capacity is 12.
[a]RESERVE
[b]DISPLAY
[c]PRINT
[d]QUIT

Here's what i've made so far.. (Sorry i'm a noob)
```//Structure Problem

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void reserve();
void display();
void print();

typedef struct data{
char surname[20];
char firstname[20];
char age[3];
char gender[6];
char date[30];
char time[20];
char destination[30];
char point_of_origin[30];
char accomodation[15];
char contact_number[11];
}INFO;
int main(void)
{
int x;
char choice;
char *a,*b,*c,*d,*e,*f,*g,*h;
for(x=0;x<12;x++)
{
a="* WELCOME TO BLAH AIRLINES *";
c="* [a] RESERVE				*";
d="* [b] DISPLAY					*";
e="* [d] PRINT					*";
f="* [q] QUIT					*";
g="****************************";
printf("\n%s\n%s\n\n%s\n%s\n%s\n%s\n\n%s\n%s",a,b,c,d,e,f,g,h);
choice=getche();
switch(choice)
{
case 'a':
if(x>0)
{
break;
}
else
reserve();
break;
case 'b':
display();
break;
case 'c':
print();
break;
case 'q':
exit(0);
default:
printf("\n\nWrong key!\n\n");
}
}
getch();
return 0;
}
void reserve()
{

INFO passenger[12];
int x;
for(x=0;x<12;x++)
{
fflush(stdin);
printf("\n\n***** RESERVATION FORM *****");
printf("\n\n//PASSENGER[%d]//\n",x);
printf("Surname		 : ");
gets(passenger[x].surname);
printf("Firstname	   : ");
gets(passenger[x].firstname);
printf("Age			 : ");
gets(passenger[x].age);
printf("Gender		  : ");
gets(passenger[x].gender);
printf("Date			: ");
gets(passenger[x].date);
printf("Time			: ");
gets(passenger[x].time);
printf("Destination	 : ");
gets(passenger[x].destination);
printf("Point of origin : ");
gets(passenger[x].point_of_origin);
printf("Accomodation	: ");
gets(passenger[x].accomodation);
printf("Contact Number  : ");
gets(passenger[x].contact_number);
}
printf("Fully Booked!\n\n");
return;
}
void display()
{
int x;						   //IT DISPLAYS FUNNY CHARACTERS ..

printf("\nEnter passenger#: ");
scanf("%d",&x);
INFO passenger[x];

printf("\n\n//PASSENGER[%d]//\n",x);
printf("Surname		 : ");
puts(passenger[x].surname);
printf("Firstname	   : ");
puts(passenger[x].firstname);
printf("Age			 : ");
puts(passenger[x].age);
printf("Gender		  : ");
puts(passenger[x].gender);
printf("Date			: ");
puts(passenger[x].date);
printf("Time			: ");
puts(passenger[x].time);
printf("Destination	 : ");
puts(passenger[x].destination);
printf("Point of origin : ");
puts(passenger[x].point_of_origin);
printf("Accomodation	: ");
puts(passenger[x].accomodation);
printf("Contact Number  : ");
puts(passenger[x].contact_number);
printf("\n\n");
return;
}
void print()
{
//I DON'T KNOW HOW TO PRINT THIS..
return;
}

```

This post has been edited by philboy: 06 March 2009 - 11:24 PM

Is This A Good Question/Topic? 0

Replies To: HELP with Structure Problem in C!

#2 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

Re: HELP with Structure Problem in C!

Posted 06 March 2009 - 11:53 PM

This post has been edited by horace: 07 March 2009 - 12:04 AM

#3 cmaster

Reputation: 2
• Posts: 53
• Joined: 18-November 08

Re: HELP with Structure Problem in C!

Posted 06 March 2009 - 11:54 PM

Do you mean printing to the printer device?

#4 philboy

Reputation: 0
• Posts: 2
• Joined: 06-March 09

Re: HELP with Structure Problem in C!

Posted 07 March 2009 - 12:08 AM

cmaster, on 6 Mar, 2009 - 10:54 PM, said:

Do you mean printing to the printer device?

yes.

The problem is when I display the info of every passenger, the output are funny characters. And, I also don't know how to print the passenger info to the printer. I'm using Dev-C++ by the way.