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" );
	}	


}

also the names on the list can only arrive once.


thx eleet

I found one syntactical problem in your PrintAttendance function, and a few logical problems in the program. You have one too many curly brackets on the function :)

Logical problems.. you may wish to include the guest input in some kind of loop, it only asks for one, then displays the one you ask for, then displays the list with absence noted.

//inside main
       String ExitString("QUIT");
        do
       {
		PromptForGuest (inputName);
	} while(inputName != ExitString)
		PrintAllNames (guest);
	//end change in main	
	

	


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);
	//Are you intentionally listing the guest's who are present here?
        // makes it go like this:
        // Please input guest name:
        //Guest name mirrored here:
        // Please input guest name:  etc...
	printf("%s\n", inputName);
	
}
void PrintAttendance ( GuestRec inName )

   
	{
		if ( inName.presence == 0 )
			printf ( "ABSENT\n" );
		else
			printf ( "PRESENT\n" );
	}	

//deleted additional curly bracket...these changes work in my compiler

I get some errors when compiling with the the code;

//inside main
       String ExitString("QUIT");
        do
       {
		PromptForGuest (inputName);
	} while(inputName != ExitString)
		PrintAllNames (guest);
	//end change in main

'String' : illegal use of this type as an expression see declaration of 'String'(this error shows up twice)
syntax error : missing ';' before identifier 'ExitString'
ExitString' undefined; assuming extern returning int
'!=' : 'char *' differs in levels of indirection from 'void (__cdecl *)(struct GuestRec *)'

C isn't C++, so C doesn't have constructors or the std::string type. You may get away with something like this.

String ExitString = "QUIT";
   /* ... */
   do
   {
      PromptForGuest (inputName);
   } while ( strcmp(inputName, ExitString) );

Personally, I don't care for the String typedef, I think it obfuscates the code and helps confuse you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.