the edit function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanielTNBaker
    New Member
    • Feb 2007
    • 7

    the edit function

    my code adds people it deletes people it can even search for people but can it edit people......nop e!

    well this is what i got so far:
    Code:
    {
       char name_val[30];
       struct client_struct client_rec;
       FILE * client_file;
       clrscr();
    
       gotoxy(10,5);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,7);
       textcolor(15);
       cprintf("Edit a Client");
       gotoxy(10,9);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,23);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,13);
       textcolor(15);
       cprintf("Enter the Name of the Client Your Editing: ");
       gotoxy(50,15);
       gets(name_val);
       client_file = fopen(CLIENTS, "rb+"); /*open .dat file*/
    
       clrscr();
    
       gotoxy(10,5);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,7);
       textcolor(15);
       cprintf("Edit the Clients Details");
       gotoxy(10,9);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,37);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,9);
       textcolor(15);
    
       while(fread(&client_rec, sizeof(client_rec), 1, client_file))
       {
          if(strcmp(name_val,client_rec.name)==0)
          {
    	 printf("\n\n\n\t\tPlease Enter the Name of the Client: ");
    	 fflush(stdin);
    	 gets(client_rec.name);
    	 printf("\n\t\tPlease Enter the Treatment for the Client: ");
    	 printf("\n\t\tF = Full Body Massage,");
    	 printf("\n\t\tB = Back Massage,");
    	 printf("\n\t\tM = Manicure,");
    	 printf("\n\t\tP = Pedicure,");
    	 printf("\n\t\tD = Pamper Day: ");
    	 client_rec.treatment = getche();
    	 printf("\n\n\t\tPlease Enter the Time of the Appointment: ");
    	 scanf("%f", &client_rec.time);
    	 printf("\n\n\t\tPlease Enter the Day (1 = Monday, 2 = Tuesday etc): ");
    	 scanf("%d", &client_rec.day);
    	 printf("\n\n\t\tPlease Enter a Contact Number for the Client: ");
    	 scanf("%f", &client_rec.contact);
          }
       }
       textcolor(15);
       fclose(client_file);
    
       getch();
    
    }
    ive been told that i should use a do while loop

    anyone got any ideas for this?
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by DanielTNBaker
    my code adds people it deletes people it can even search for people but can it edit people......nop e!

    well this is what i got so far:
    Code:
    {
       char name_val[30];
       struct client_struct client_rec;
       FILE * client_file;
       clrscr();
    
       gotoxy(10,5);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,7);
       textcolor(15);
       cprintf("Edit a Client");
       gotoxy(10,9);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,23);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,13);
       textcolor(15);
       cprintf("Enter the Name of the Client Your Editing: ");
       gotoxy(50,15);
       gets(name_val);
       client_file = fopen(CLIENTS, "rb+"); /*open .dat file*/
    
       clrscr();
    
       gotoxy(10,5);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,7);
       textcolor(15);
       cprintf("Edit the Clients Details");
       gotoxy(10,9);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,37);
       textcolor(1);
       cprintf("-------------------------------------------------");
       gotoxy(10,9);
       textcolor(15);
    
       while(fread(&client_rec, sizeof(client_rec), 1, client_file))
       {
          if(strcmp(name_val,client_rec.name)==0)
          {
    	 printf("\n\n\n\t\tPlease Enter the Name of the Client: ");
    	 fflush(stdin);
    	 gets(client_rec.name);
    	 printf("\n\t\tPlease Enter the Treatment for the Client: ");
    	 printf("\n\t\tF = Full Body Massage,");
    	 printf("\n\t\tB = Back Massage,");
    	 printf("\n\t\tM = Manicure,");
    	 printf("\n\t\tP = Pedicure,");
    	 printf("\n\t\tD = Pamper Day: ");
    	 client_rec.treatment = getche();
    	 printf("\n\n\t\tPlease Enter the Time of the Appointment: ");
    	 scanf("%f", &client_rec.time);
    	 printf("\n\n\t\tPlease Enter the Day (1 = Monday, 2 = Tuesday etc): ");
    	 scanf("%d", &client_rec.day);
    	 printf("\n\n\t\tPlease Enter a Contact Number for the Client: ");
    	 scanf("%f", &client_rec.contact);
          }
       }
       textcolor(15);
       fclose(client_file);
    
       getch();
    
    }
    ive been told that i should use a do while loop

    anyone got any ideas for this?
    I would agree with using a while loop, I would also suggest getting rid of getch() , but that's a personal issue - several compilers are ok with it...

    Comment

    Working...