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             

Line 89 is the problem.

commented: One cannot have an unbounded switch statement without cases and properly braced. +13

I should also add that, strictly speaking, in C prior to the C99 standard, all declarations within a function needed to be made before any other statements. I only bring this up because you #include <conio.h>; the console I/O library is not a standard part of C, and is associated with older (that is, pre-C99) Borland compilers. Those compilers shouldn't let you do both.

the console I/O library is not a standard part of C, and is associated with older (that is, pre-C99) Borland compilers.

Some common modern compilers support it. I don't see any clear indication that this is a pre-C99 compiler, though use of fflush(stdin) narrows things down a bit as well.

That said, if the compiler supports a C99 feature and doesn't use any non-C99 features, what's the problem? I can only see an issue if the code is intended to be C90 compatible.

Of larger concern is fflush(stdin), which is technically undefined behavior across the board, and use of gets, which is abhorrent regardless of compiler and non-standard as of C11.

commented: Yes, fflush() is meant for output streams. Stdin is an input stream. +13
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.