i have a code which asks creates a structures and then for each it will check if the
asks the user to enter a name and it will check if the name already exists within the database. if the name can be found ,
it will asks the user to modify the name or adress.
for some reason i am getting don is undefined for the line don[i]=get_info();
# include <stdio.h >
# include <conio.h>
# include <string.h>
# define last 10
struct donor
{
char name[20];
char adress[20];
int phone;
char type[20];
float donation;
};
struct donor get_info() //function get_info
{
struct donor temp; //declare temporary storage – structure temp of donor type
fflush(stdin);
printf("\nEnter the donation name :");
gets(temp.name); //get student name
fflush(stdin);
printf("\nEnter the donation type :");
gets(temp.type); //get student name
fflush(stdin);
printf("\nEnter the donation adress :");
gets(temp.adress); //get student name
fflush(stdin);
/*
printf("Enter the adress :");
scanf("%d", &temp.adress); //enter student registration number */
printf("Enter the phone number :");
scanf("%d", &temp.phone); //enter student registration number
printf("Enter the donation amount :");
scanf("%f", &temp.donation); //enter student tuition
return temp; //return structure temp to main
}
void display(struct donor donor[]) //function display;
{ // structure of student type is passed to a function display
int i;
printf("\n%-20s %10s %10s", "Name", "Registration #", "Tuition");
for(i=0; i< last ; i++) //use for loop to print members of all structures within array
printf("%s %s %i %s %f ", donor[i].name, donor[i].adress, donor[i].phone, donor[i].type , donor[i].donation ) ;
}
int main(void)
{
int i;
char input[20], input2[20];
printf("Make a Selection");
gets(input);
switch(input)
static struct donor don[last] ;
for(i=0;i<last;i++)
{
don[i]=get_info(); //call function get_info for each structure within array
}
printf(" Enter the name of the Donor ") ;
gets(donor.name);
fflush(stdin);
bool flag = false;
for(i=0;i=last;i++)
{
// is found within record exists
//donor.name == name entered by user
// donor[i].name structure created by for loop
// if they are equal record exist
if (donor.name == donor[i].name )
{ flag = true; // record exists , set flag to true
// activate switch
printf(" Enter if you wish to modify name/adress/phone/type/donation ") ;
gets(input);
switch(input)
{
case 'Name' :
printf("modify donor's name \n" );
scanf("%s", donor.name) ;
break;
case 'Adress' :
printf("modify donor's adress \n" );
scanf("%s", donor.adress) ;
break;
case 'Phone' :
printf("modify donor's phone \n" );
scanf("%i", donor.phone) ;
break;
case 'Type' :
printf("modify donor's type \n" );
scanf("%s", donor.type) ;
break;
case 'Donation' :
printf("modify donor's donation \n" );
scanf("%f", donor.donation) ;
break;
default :
printf("Invalid Selection" );
} // close switch
} // close if
} // close main