I have this program that I have written in C that when I compile and run the program it run thru asking for the data to be entered then when I am done entering the information in it displays on the screen. When I hit any key to exit I get an error.
Can some one help me on figuring out what is causing my program not to exit correctly.
Code:
Can some one help me on figuring out what is causing my program not to exit correctly.
Code:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct guest {
int age;
char lastname[30];
};
struct guest* guestlist_allocate(int number);
void guestlist_deallocate(struct guest* p, int number);
void guestlist_readall(struct guest* p, int number);
void guestlist_display(struct guest* p, int number);
int main()
{
int n = 3;
struct guest* guestlist;
printf("How many guests do you need to enter? ");
scanf("%d", &n);
guestlist_allocate;
while(n <= 0)
{
printf("Error you entered a negative number!");
break;
}
printf("Reading data for %d guests\
", n);
guestlist_readall(guestlist, n);
printf("Displaying data for %d guests\
", n);
guestlist_display(guestlist, n);
guestlist_deallocate;
system("PAUSE");
return 0;
}
struct guest* guestlist_allocate(int number)
{
char lastname;
int age = 0;
int n;
char buffer[30];
struct guest *guestlist;
guestlist = malloc (sizeof(struct guest) * n);
strcpy(lastname,buffer);
}
void guestlist_deallocate(struct guest* p, int number)
{
int i;
int n;
struct guest *guestlist;
for (i = 0; i < n; i++)
free(p[i].lastname);
free(guestlist);
}
void guestlist_readall(struct guest* p, int number)
{
char lastname;
int age=0;
int i;
for( i = 0; i < number; i++)
{
printf("\Guest #%d:\
", i);
printf("\\Enter lastname: ");
scanf("%29s", p[i].lastname);
printf("\\Enter age: ");
scanf("%ld", &p[i].age);
}
}
void guestlist_display(struct guest* p, int number)
{
int i;
for(i = 0; i < number; i++)
printf("\Guest #%d: lastname = %s\age = %ld\
", i, p[i].lastname, p[i].age);
}