Thread: Code being passed over / need help

  1. #1
    zach
    Guest

    Code being passed over / need help

    Code:
        locate(5,8);char codeIn[10]; printf("Code");locate(30,8);printf(": ");
                fgets(codeIn, sizeof(codeIn),stdin);
                if ( (p = strchr(codeIn,'\n')) != NULL ) *p = '\0';
            
                strcpy(B.bill, billIn);    
                strcpy(B.date, dateIn);    
                strcpy(B.descr, descrIn);    
                strcpy(B.euros, eurosIn);
                strcpy(B.code, codeIn);
    
                FILE *C;
                C = fopen("data2","ab");
                fwrite(&B,sizeof(struct A),1,C);
                fclose(C);
                
                locate(6,23);printf("%s %s %s %s %s",billIn, dateIn, descrIn, eurosIn, codeIn);
                locate(6,24);printf("The above has been saved to disk");
                        
                int c;
                printf("Continue y / n : ");
                c = getchar();
        
                if (c == 'y' || c == 'Y') 
                {
                      // do something
                }
                else
                {


    Depending on the number of characters keyed in during the last data input, the request for Y/N will be skipped over. What to do about this? Zach K.
    Last edited by zach; 08-30-2019 at 04:03 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-28-2017, 07:19 AM
  2. String not being passed
    By Jedd Lim in forum C Programming
    Replies: 6
    Last Post: 09-23-2015, 08:51 PM
  3. Replies: 4
    Last Post: 03-26-2014, 03:11 PM
  4. Replies: 0
    Last Post: 12-04-2011, 11:29 PM
  5. int value passed to function
    By search in forum C Programming
    Replies: 7
    Last Post: 03-10-2010, 06:05 PM

Tags for this Thread