Dear all,
i am trying to make a scheduler program. so in the following code the part where
Code:
          if(op == 2)  
             printf("ENTER descrption, start time and duration.\n");
              fgets(desc,100,stdin); 
              scanf("%d%*d",&start_h);  
              scanf("%d%*d",&dur);       
              add(appo,desc,start_h,dur);
is for adding appointments to a structure with the add fucntion.
in this part i ask for a description of the appointment, the start time and the duration.
to ask for the description, i am using the fgets(); function. but the program terminates at this point saying "schedule.exe has stopped working".

this entire part is inside the main, inside an infinite loop like this

Code:
 
char desc[100];
int start_h,dur,clash,op;

while(1)
  {
   printf("SHOW - 1,ADD - 2,DEL - 3 appointments, QUIT - 4\n");
   scanf("%d",&op);
    
   if(op == 1)
    {
     printf("\n If NOT shown then FREE\n\n"); 
     show(appo);
    } 
   if(op == 2) 
    {
     printf("ENTER descrption, start time and duration.\n");
     fgets(desc,100,stdin);                        // PROGRAM TERMINATES HERE
scanf("%d%*d",&start_h);
 scanf("%d%*d",&dur);

 clash = add(appo,desc,start_h,dur);
     
     
     if(clash == 1)
      {
       printf("\n\tWARNING : UNABLE to add due to CLASHES\n");
      }
     else
      {
       printf("\n\tSUCCESSFULLY added to schedule\n");
      } 
    }
   if(op == 3)
    {
     printf("op 3\n"); 
    }
    
   if(op == 4) 
    {
     return 0;
    }
  }
so i want to know why it terminates and how to get the description which is 1 line long? thanks for your help.

for your reference
Code:
struct appointments 
{
 char desc[100];                    
 int start_h;
 int dur;
};
the add function for your reference.
Code:
int add(struct appointments appo[24],char desc[100],int start_h,int dur)
{
 int var = start_h;

 if(!strcmp((appo[start_h].desc),"FREE"))
  {
   strcpy((appo[start_h].desc),desc);
   (appo[start_h].start_h) = start_h;
   (appo[start_h].dur) = dur;
   
   while(var <= (start_h + dur))
   {
    strcpy((appo[var].desc),"Continued | Occupied");
    (appo[var].start_h) = start_h;
    (appo[var].dur) = dur;  
    var++;
   }
   return 0; 
  }
 else
  return 1;
}

Last edited by jose_peeterson; 14Dec2011 at 09:23..