Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,924 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,823 people online right now. Registration is fast and FREE... Join Now!




PASSING ARRAY TO A FUNCTION

 
Reply to this topicStart new topic

PASSING ARRAY TO A FUNCTION, HOW DO I PASS A STRING TO A FUNCTION FROM A STRUCTURE

lenoy
31 Mar, 2008 - 05:11 PM
Post #1

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 11

cpp

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

#define MAX 50
#define SMOKING 4000
#define NON_SMOKING 3000

char smoking,nonsmoking;



typedef struct
{
char RoomType[20];
int RoomNum;
int status;
}room[MAX];

typedef struct
{
char FName[20];
char LName[20];
int lenght_stay;
int CreditCardNo[16];
}guest[MAX];

//struct room[MAX];
//struct guest[MAX];

//room[MAX]={" ",0,0}; //array structure


char menu();
void code_Change();
void Reservation();
int RmStatus(char[]);

int main()
{
char option,q;

printf("\t**********Welcome to SouthCoast Serenity Inn database.**********\n\n\n");

option = menu();

while(option!='q')
{
switch(option)
{
case'r':
case'R':
Reservation();
break;

case'c':
case'C':
break;

case'q':
exit(0);
break;

default:
break;
}
option=menu();
}
getch();
return 0;
}


char menu()
{

char opt;

printf("\tPlease select character that represents your choice.\n\n");
printf("\tSelect ® to make resevation\n\tSelect © to cancle reservation");
printf("\n\tSelect (i) to check in \n\tSelect (o) for checking out\n\t");
printf("Select (x) to exit");
printf("\n\t");
scanf("%c",opt);
return opt;
}

/******************************************************************************
make reservation
********************************************************************************
/


void Reservation()
{
int x =0;
int chk;


printf("\t\tEnter selection displayed\n\n");
printf("First name: \n" );
gets(guest[x].FName);
printf("Last name: \n" );
gets(guest[x].LName);
printf("Credit card number\n");
scanf("%d",&guest[x].CreditCardNo);
printf("Prefered room type\n");
gets(room[x].RoomType);
/* FILE *freserv;

if((freserv = fopen("reservation.txt","w+"))== NULL)
{
printf("Error opening file....");

}
*/

chk = RmStatus(char room[].RoomType);

printf("\t\tRoom now reserved.......\n");
if(chk == 0)
printf("Room Empty\n");
room[x].status=1;



//for(int i=0;i<50;i++)
//fclose(freserv);
x++;
}

/******************************************************************************
check room status
*******************************************************************************/
int RmStatus(char room[].RoomType)
{
if(type == smoking){

for(int i=0;i<25;i++){

if(room[i].status==0){
return 0;
//break;
}


if(room[i].status==1){
return 1;
//break;
}

if(room[i].status==2){
return 2;
// break;
}
}
}


if(type == nonsmoking){

for(int j=0;j>24;j++){

if(room[j].status==0){
return 0;
//break;
}

if(room[j].status==1){

return 1;
//break;
}
if(room[j].status==2){

return 2;
//break;
}
}
}


}

*edit: Please use code tags in the future, thanks! code.gif

This post has been edited by Martyr2: 31 Mar, 2008 - 09:50 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:19PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month