I first read in data from a file. Then the user is prompted for a name of a person trying to enter the party. If the name of a person trying to get in does not match any name on the invitation list, the program should print a message indicating that the person may not attend the party. The user must enter the word QUIT (in all upper-case) to end this interactive input of names.
Then print a report showing how many of the invited showed up, how many people who tried to enter were denied permission to attend, and a summary table giving a list of all the names of invited persons, with either Present or Absent after each name
At the moment I am having touble show when the guest on the list arrives and makes them Present.
The function that I wrote for this part is called PrintAttendance.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define DataFile 25
#define STRING_LENGTH 30
typedef enum Attendance {ABSENT,PRESENT} Attendance;
typedef char String [STRING_LENGTH];
typedef struct GuestRec
{
String name; /* you must also declare a typedef'd string type to use here */
Attendance presence; /* you must declare the enum type to use here */
} GuestRec;
typedef GuestRec GuestList[DataFile];
void ReadGuestRec (GuestList guest);
void PrintAllNames (GuestList guest);
void PromptForGuest (String inputName);
void PrintAttendance ( GuestRec inName );
int main()
{
GuestList guest;
String inputName;
printf("************************************************\n");
printf(" Welcome to the Party Security Program\n");
printf("************************************************\n\n");
/* read all guest names*/
ReadGuestRec( guest);
PromptForGuest (inputName);
PrintAllNames (guest);
/* print goodbye message */
printf ("Execution Terminated.\n\n");
return ( 0 );
}
void ReadGuestRec (GuestList guest)
{
int lcv;
FILE* infile; /* input data file */
/* open data file, abort run if can't open */
infile = fopen ( "partyGuests.txt", "r" );
if (!infile)
{
printf ( "Fatal Error: Data file could not be opened\n\n" );
exit (EXIT_FAILURE);
}
for (lcv=0; lcv < DataFile; lcv++ )
{
fgets ( guest [lcv].name, STRING_LENGTH, infile );
guest[lcv].name [strlen (guest[lcv].name) - 1] = '\0';
guest[lcv].presence = ABSENT;
printf("%s\n", guest[lcv].name);
}
fclose ( infile );
}
void PrintAllNames (GuestList guest)
{
int lcv;
for(lcv = 0; lcv < DataFile; lcv++)
{
printf("%s\n", guest[lcv].name);
PrintAttendance (guest[lcv]);
}
}
void PromptForGuest (String inputName)
{
String firstName;
String lastName;
printf("\nPlease enter Guest Name: ");
scanf("%s %s", firstName, lastName);
inputName = strcat(firstName," ");
inputName = strcat(inputName,lastName);
printf("%s\n", inputName);
}
void PrintAttendance ( GuestRec inName )
{
if ( inName.presence == 0 )
printf ( "ABSENT\n" );
else
printf ( "PRESENT\n" );
}
}