Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Exclamation Hotel Management Program


    I have made a program for hotel management. It has a problem that: In the Accounts function, it should reset all the flags of the registered members through the program. But there is a error that it does NOT. I have spent a lot of weeks, trying to debug this problem, but i couldn't. So please help me. Here is the code of the account function,
    Code:
    void accounts()
    {
        int ttt=0;
        struct person payment;
        char aname[21], oname[21];
        char *namea;
        int chec=1, ver=0;
        long int recsize;
        recsize=sizeof(payment);
        f=fopen("C:\\HOTEL.DAT", "rb+");
        if(f == NULL){
            clrscr();
            cprintf("File could not be opened!");
            sleep(4);
            exit(0);
        }
        clrscr();
        cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
        cprintf("\r\r\rEnter the Name :");
        fflush(stdin);
        scanf("%[^\n]s", &aname);
        namea=strupr(aname);
        strcpy(oname, namea);
        while(fread(&payment, recsize, 1, f) == 1){
    
            if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
                payment.pay=1;
                printf("\n\n Payment Received");
                fflush(stdin);
                getch();
                ver=1;
    
                fseek(f, -recsize, SEEK_CUR);
                fwrite(&payment, sizeof(payment), 1, f);
                break;
    
            }
    
        }
    
        if(ver!=1){
            printf("\n\n Record not Found!!!");
            fflush(stdin);
            getch();
        }
        //rewind(f);
        fclose(f);
        f=fopen("C:\\HOTEL.DAT", "rb+");
        if(f == NULL){
            clrscr();
            cprintf("File could not be opened!");
            sleep(4);
            exit(0);
        }
    
        while(fread(&payment, recsize, 1, f) == 1){
            if(payment.pay==0){
                chec=0;
                break;
            }
        }
        //rewind(f);
        f=fopen("C:\\HOTEL.DAT", "rb+");
        if(f == NULL){
            clrscr();
            cprintf("File could not be opened!");
            sleep(4);
            exit(0);
        }
    
        if(chec==1){
                while(fread(&payment, recsize, 1, f) == 1){
                    payment.pay=0;
                    fseek(f, -recsize, SEEK_CUR);
                    fwrite(&payment, recsize, 1, f);
                    ttt++;
                    printf("%d", ttt);
                }
    
                printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0");
                fflush(stdin);
                getch();
        }
        printf("Before Fclose");
        fclose(f);
        printf("After Fclose");
    }
    Please help ASAP. Eagerly waiting for an answer. Thanks in advance. Daksh Shah
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    > struct person payment;
    Does this contain any pointers - like say a char*
    If it does, then your simple fread/fwrite code will not work.

    > fflush(stdin);
    Lemme guess, another TurboC user.
    You should really upgrade to something for this millennium, but I'm guessing from your name that your school and entire education system is stuck in the past. Blame your bureaucracy, where no one ever gets fired for showing a lack of initiative, and meekly towing the line (no matter how stupid) is rewarded.

    Code:
    $ egrep 'fopen|fclose|fread|fwrite' foo.c
        f=fopen("C:\\HOTEL.DAT", "rb+");
        while(fread(&payment, recsize, 1, f) == 1){
                fwrite(&payment, sizeof(payment), 1, f);
        fclose(f);
        f=fopen("C:\\HOTEL.DAT", "rb+");
        while(fread(&payment, recsize, 1, f) == 1){
        f=fopen("C:\\HOTEL.DAT", "rb+");
                while(fread(&payment, recsize, 1, f) == 1){
                    fwrite(&payment, recsize, 1, f);
        fclose(f);
    a) why do you keep opening and closing the file?
    b) why do you open it twice, without closing it?
    You should be able to just open and close the file once, and then use rewind(f), which you did at least try once, to go back to the start of the file each time you need to.

    Code:
                while(fread(&payment, recsize, 1, f) == 1){
                    payment.pay=0;
                    fseek(f, -recsize, SEEK_CUR);
                    fwrite(&payment, recsize, 1, f);
    See, this is a place where you SHOULD use fflush()
    Specifically, after the fwrite, you do
    fflush(f);
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Still there is the same problem.


    @salem
    Hi,
    I have changed the code as you said, but it didnt change the output. Here's the code
    Code:
    void accounts()
    {
    	int ttt=0;
    	struct person payment;
    	char aname[21], oname[21];
    	char *namea;
    	int chec=1, ver=0;
    	long int recsize;
    	recsize=sizeof(payment);
    	f=fopen("C:\\HOTEL.DAT", "rb+");
    	if(f == NULL){
    		clrscr();
    		cprintf("File could not be opened!");
    		sleep(4);
    		exit(0);
    	}
    	clrscr();
    	cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
    	cprintf("\r\r\rEnter the Name :");
    	fflush(stdin);
    	scanf("%[^\n]s", &aname);
    	namea=strupr(aname);
    	strcpy(oname, namea);
    	while(fread(&payment, recsize, 1, f) == 1){
    
    		if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
    			payment.pay=1;
    			printf("\n\n Payment Received");
    			fflush(stdin);
    			getch();
    			ver=1;
    
    			fseek(f, -recsize, SEEK_CUR);
    			fwrite(&payment, sizeof(payment), 1, f);
    			fflush(f);
    			break;
    
    		}
    
    	}
    
    	if(ver!=1){
    		printf("\n\n Record not Found!!!");
    		fflush(stdin);
    		getch();
    	}
    	rewind(f);
    	if(f == NULL){
    		clrscr();
    		cprintf("File could not be opened!");
    		sleep(4);
    		exit(0);
    	}
    
    	while(fread(&payment, recsize, 1, f) == 1){
    		if(payment.pay==0){
    			chec=0;
    			break;
    		}
    	}
    	//rewind(f);
    	f=fopen("C:\\HOTEL.DAT", "rb+");
    	if(f == NULL){
    		clrscr();
    		cprintf("File could not be opened!");
    		sleep(4);
    		exit(0);
    	}
    
    	if(chec==1){
    			while(fread(&payment, recsize, 1, f) == 1){
    				payment.pay=0;
    				fseek(f, -recsize, SEEK_CUR);
    				fwrite(&payment, recsize, 1, f);
    				ttt++;
    				printf("%d", ttt);
    			}
    
    			printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0");
    			fflush(stdin);
    			getch();
    	}
    	printf("Before Fclose");
    	fclose(f);
    	printf("After Fclose");
    }
    Tell me is something is still wrong.
    (BTW: thanks for trying to help)
    Reply ASAP.
    The problem in the output is: this time i had to structures in my file.
    When, I set both the payment flags by entering the names;
    i does display the message "All payments received" but i resets the flag of only 1 structure.
    Daksh Shah

    Comments on this post

    • mythos_ disagrees : Reply ASAP? if u want help better stop that commanding tone...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Bhopal
    Posts
    3
    Rep Power
    0
    Thanks for this code i am very worried about that this code was not getting me so thanks for that
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by soniarhode
    Thanks for this code i am very worried about that this code was not getting me so thanks for that
    what? i couldnt understand what u said..?
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    You didn't post your "struct person".

    You're still opening the file TWICE and only closing it once.

    You still have fflush(stdin) all over the place.

    There is still one fread/fwrite loop WITHOUT a fflush(f) call in it.
    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
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Struct Person


    Originally Posted by salem
    You didn't post your "struct person".
    Here is my struct person:
    struct s_office{
    char name[16];
    char phone[12];
    };
    struct permanent{
    char addr[100];
    char phone[12];
    };

    struct emergency{
    char name[21];
    char relation[11];
    char phone[12];
    };

    struct person{
    char name[21];
    char phone[12];
    char place[21];
    int roomno;
    int flag;
    char food;
    struct s_office office;
    char father[21];
    char fphone[12];
    struct permanent per;
    struct emergency emer1;
    char email[40];
    int finger;
    char dob[8];
    int cidate;
    int cimonth;
    int ciyear;
    int codate;
    int comonth;
    int coyear;
    int rent;
    int pay;
    };
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    FOPEN Replaced by REWIND


    Originally Posted by salem
    You're still opening the file TWICE and only closing it once.
    void accounts()
    {
    int ttt=0;
    struct person payment;
    char aname[21], oname[21];
    char *namea;
    int chec=1, ver=0;
    long int recsize;
    recsize=sizeof(payment);
    f=fopen("C:\\HOTEL.DAT", "rb+");
    if(f == NULL){
    clrscr();
    cprintf("File could not be opened!");
    sleep(4);
    exit(0);
    }
    clrscr();
    cprintf("\n *** Pearl Guest House - Payments ***\n\n");
    cprintf("\r\r\rEnter the Name :");
    fflush(stdin);
    scanf("%[^\n]s", &aname);
    namea=strupr(aname);
    strcpy(oname, namea);
    while(fread(&payment, recsize, 1, f) == 1){

    if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
    payment.pay=1;
    printf("\n\n Payment Received");
    fflush(stdin);
    getch();
    ver=1;

    fseek(f, -recsize, SEEK_CUR);
    fwrite(&payment, sizeof(payment), 1, f);
    fflush(f);
    break;

    }

    }

    if(ver!=1){
    printf("\n\n Record not Found!!!");
    fflush(stdin);
    getch();
    }
    rewind(f);
    if(f == NULL){
    clrscr();
    cprintf("File could not be opened!");
    sleep(4);
    exit(0);
    }

    while(fread(&payment, recsize, 1, f) == 1){
    if(payment.pay==0){
    chec=0;
    break;
    }
    }
    rewind(f);
    if(f == NULL){
    clrscr();
    cprintf("File could not be opened!");
    sleep(4);
    exit(0);
    }

    if(chec==1){
    while(fread(&payment, recsize, 1, f) == 1){
    payment.pay=0;
    fseek(f, -recsize, SEEK_CUR);
    fwrite(&payment, recsize, 1, f);
    ttt++;
    printf("%d", ttt);
    }

    printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0");
    fflush(stdin);
    getch();
    }
    fclose(f);
    }
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by salem
    You didn't post your "struct person".

    You're still opening the file TWICE and only closing it once.

    You still have fflush(stdin) all over the place.

    There is still one fread/fwrite loop WITHOUT a fflush(f) call in it.
    Did all u said, still the same output. PLEASE CHECK
    Code:
    void accounts()
    {
    	int ttt=0;
    	struct person payment;
    	char aname[21], oname[21];
    	char *namea;
    	int chec=1, ver=0;
    	long int recsize;
    	recsize=sizeof(payment);
    	f=fopen("C:\\HOTEL.DAT", "rb+");
    	if(f == NULL){
    		clrscr();
    		cprintf("File could not be opened!");
    		sleep(4);
    		exit(0);
    	}
    	clrscr();
    	cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
    	cprintf("\r\r\rEnter the Name :");
    	fflush(stdin);
    	scanf("%[^\n]s", &aname);
    	namea=strupr(aname);
    	strcpy(oname, namea);
    	while(fread(&payment, recsize, 1, f) == 1){
    
    		if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
    			payment.pay=1;
    			printf("\n\n Payment Received");
    			//fflush(stdin); commented afterwards
    			getch();
    			ver=1;
    
    			fseek(f, -recsize, SEEK_CUR);
    			fwrite(&payment, sizeof(payment), 1, f);
    			fflush(f);
    			break;
    
    		}
    		fflush(f); //new one
    	}
    
    	if(ver!=1){
    		printf("\n\n Record not Found!!!");
    		//fflush(stdin); commented afterwards
    		getch();
    	}
    	rewind(f);
    	if(f == NULL){
    		clrscr();
    		cprintf("File could not be opened!");
    		sleep(4);
    		exit(0);
    	}
    
    	while(fread(&payment, recsize, 1, f) == 1){
    		if(payment.pay==0){
    			chec=0;
    			break;
    		}
    	}
    	rewind(f);
    	
    
    	if(chec==1){
    			while(fread(&payment, recsize, 1, f) == 1){
    				payment.pay=0;
    				fseek(f, -recsize, SEEK_CUR);
    				fwrite(&payment, recsize, 1, f);
    				ttt++;
    				printf("%d", ttt);
    				fflush(f); //new one
    			}
    
    			printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0");
    			fflush(stdin);
    			getch();
    	}
    	fclose(f);
    }
    Reply ASAP
  18. #10
  19. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    I think you need to have a good look at what your 'pay' and 'flag' variables are really for.

    It seems to me that unless you only have one paying customer, your chec=0 is always going to happen, and this stops the final loop from running at all.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    // redefine all the conio rubbish
    #define clrscr()
    #define cprintf printf
    #define getch getchar
    
    struct person {
      int pay;
      char name[21];  //!! if your name is a pointer, you're screwed anyway
      int flag;
    };
    
    char *strupr ( char *s ) {
      //!! strupr() is a non-standard function, so I settled for
      //!! just typing in the name correctly
      return s;
    }
    
    void accounts()
    {
      int ttt=0;
      struct person payment;
      char aname[21], oname[21];
      char *namea;
      int chec=1, ver=0;
      long int recsize;
      recsize=sizeof(payment);
      FILE *f=fopen("HOTEL.DAT", "rb+");
      if(f == NULL){
        clrscr();
        cprintf("File could not be opened!\n");
        sleep(4);
        exit(0);
      }
      clrscr();
      cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
      cprintf("\r\r\rEnter the Name :");
    //  fflush(stdin);
      scanf("%[^\n]s", aname);    //!! not &
      namea=strupr(aname);
      strcpy(oname, namea);
      while(fread(&payment, recsize, 1, f) == 1){
    
        if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
          payment.pay=1;
          printf("\n\n Payment Received\n");
          //fflush(stdin); commented afterwards
          getch();
          ver=1;
    
          fseek(f, -recsize, SEEK_CUR);
          fwrite(&payment, sizeof(payment), 1, f);
          fflush(f);
          break;
    
        }
        fflush(f); //new one
      }
    
      if(ver!=1){
        printf("\n\n Record not Found!!!\n");
        //fflush(stdin); commented afterwards
        getch();
      }
      rewind(f);
    //   if(f == NULL){
    //     clrscr();
    //     cprintf("File could not be opened!\n");
    //     sleep(4);
    //     exit(0);
    //   }
    
      //!! what is this for?
      //!! if ANY .pay is 0, then this prevents your third
      //!! loop from running
      while(fread(&payment, recsize, 1, f) == 1){
        if(payment.pay==0){
          chec=0;
          break;
        }
      }
      rewind(f);
      
      if(chec==1){
          while(fread(&payment, recsize, 1, f) == 1){
            payment.pay=0;
            fseek(f, -recsize, SEEK_CUR);
            fwrite(&payment, recsize, 1, f);
            ttt++;
            printf("%d\n", ttt);
            fflush(f); //new one
          }
    
          printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0\n");
    //      fflush(stdin);
          getch();
      }
      fclose(f);
    }
    
    int main ( ) {
      struct person data[4] = {
        { 0, "Fred",    1 },
        { 0, "Barney",  0 },
        { 0, "Wilma",   0 },
        { 0, "Betty",   0 },
      };
      FILE *fp = fopen("HOTEL.DAT","wb");
      fwrite(data,sizeof(data),1,fp);
      fclose(fp);
      accounts();
      return 0;
    }
    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
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by salem
    I think you need to have a good look at what your 'pay' and 'flag' variables are really for.

    It seems to me that unless you only have one paying customer, your chec=0 is always going to happen, and this stops the final loop from running at all.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    // redefine all the conio rubbish
    #define clrscr()
    #define cprintf printf
    #define getch getchar
    
    struct person {
      int pay;
      char name[21];  //!! if your name is a pointer, you're screwed anyway
      int flag;
    };
    
    char *strupr ( char *s ) {
      //!! strupr() is a non-standard function, so I settled for
      //!! just typing in the name correctly
      return s;
    }
    
    void accounts()
    {
      int ttt=0;
      struct person payment;
      char aname[21], oname[21];
      char *namea;
      int chec=1, ver=0;
      long int recsize;
      recsize=sizeof(payment);
      FILE *f=fopen("HOTEL.DAT", "rb+");
      if(f == NULL){
        clrscr();
        cprintf("File could not be opened!\n");
        sleep(4);
        exit(0);
      }
      clrscr();
      cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
      cprintf("\r\r\rEnter the Name :");
    //  fflush(stdin);
      scanf("%[^\n]s", aname);    //!! not &
      namea=strupr(aname);
      strcpy(oname, namea);
      while(fread(&payment, recsize, 1, f) == 1){
    
        if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
          payment.pay=1;
          printf("\n\n Payment Received\n");
          //fflush(stdin); commented afterwards
          getch();
          ver=1;
    
          fseek(f, -recsize, SEEK_CUR);
          fwrite(&payment, sizeof(payment), 1, f);
          fflush(f);
          break;
    
        }
        fflush(f); //new one
      }
    
      if(ver!=1){
        printf("\n\n Record not Found!!!\n");
        //fflush(stdin); commented afterwards
        getch();
      }
      rewind(f);
    //   if(f == NULL){
    //     clrscr();
    //     cprintf("File could not be opened!\n");
    //     sleep(4);
    //     exit(0);
    //   }
    
      //!! what is this for?
      //!! if ANY .pay is 0, then this prevents your third
      //!! loop from running
      while(fread(&payment, recsize, 1, f) == 1){
        if(payment.pay==0){
          chec=0;
          break;
        }
      }
      rewind(f);
      
      if(chec==1){
          while(fread(&payment, recsize, 1, f) == 1){
            payment.pay=0;
            fseek(f, -recsize, SEEK_CUR);
            fwrite(&payment, recsize, 1, f);
            ttt++;
            printf("%d\n", ttt);
            fflush(f); //new one
          }
    
          printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0\n");
    //      fflush(stdin);
          getch();
      }
      fclose(f);
    }
    
    int main ( ) {
      struct person data[4] = {
        { 0, "Fred",    1 },
        { 0, "Barney",  0 },
        { 0, "Wilma",   0 },
        { 0, "Betty",   0 },
      };
      FILE *fp = fopen("HOTEL.DAT","wb");
      fwrite(data,sizeof(data),1,fp);
      fclose(fp);
      accounts();
      return 0;
    }
    I compiled the code that you wrote, but it gave error!
    Pls tell me what to do of the code


    Sir, can u please also explain me the code you wrote (in detail, because i couldnt get it) :)
    and tell me some books that i shud read, i have read 'let us c' and i want to master Language C so can u suggest me somethings.(n books)
    Thanks in advance
    Daksh :)
  22. #12
  23. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    I was rather hoping that you would read the code I posted, make note of the questions and comments, then apply some new knowledge to your own code.

    In particular, the part about chec ALWAYS being zero.

    But it seems you just compiled it just to say "it doesn't work"
    WTF does "it doesn't work" mean? If you don't post the error messages, we can't help.

    $ gcc foo.c
    $ ./a.out

    *** Pearl Guest House - Payments ***

    Enter the Name :Fred


    Payment Received
    $ odx HOTEL.DAT
    000000 01 00 00 00 46 72 65 64 00 00 00 00 00 00 00 00 >....Fred........<
    000010 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 >................<
    000020 00 00 00 00 42 61 72 6e 65 79 00 00 00 00 00 00 >....Barney......<
    000030 00 00 00 00 00 00 00 00 00 0d 40 00 00 00 00 00 >..........@.....<
    000040 00 00 00 00 57 69 6c 6d 61 00 00 00 00 00 00 00 >....Wilma.......<
    000050 00 00 00 00 00 00 00 00 00 0e 40 00 00 00 00 00 >..........@.....<
    000060 00 00 00 00 42 65 74 74 79 00 00 00 00 00 00 00 >....Betty.......<
    000070 00 00 00 00 00 00 00 00 00 08 40 00 00 00 00 00 >..........@.....<
    000080
    The blue number is the .pay member, which shows that person.pay = 1 happened.
    The red number is person.flag, which is set up in main.

    Because there is at least ONE record where .pay is zero, this happens
    Code:
        if(payment.pay==0){
          chec=0;
          break;
        }
    Which means this NEVER happens
    Code:
      if(chec==1){
    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
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by salem
    I was rather hoping that you would read the code I posted, make note of the questions and comments, then apply some new knowledge to your own code.

    In particular, the part about chec ALWAYS being zero.

    But it seems you just compiled it just to say "it doesn't work"
    WTF does "it doesn't work" mean? If you don't post the error messages, we can't help.

    $ gcc foo.c
    $ ./a.out

    *** Pearl Guest House - Payments ***

    Enter the Name :Fred


    Payment Received
    $ odx HOTEL.DAT
    000000 01 00 00 00 46 72 65 64 00 00 00 00 00 00 00 00 >....Fred........<
    000010 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 >................<
    000020 00 00 00 00 42 61 72 6e 65 79 00 00 00 00 00 00 >....Barney......<
    000030 00 00 00 00 00 00 00 00 00 0d 40 00 00 00 00 00 >..........@.....<
    000040 00 00 00 00 57 69 6c 6d 61 00 00 00 00 00 00 00 >....Wilma.......<
    000050 00 00 00 00 00 00 00 00 00 0e 40 00 00 00 00 00 >..........@.....<
    000060 00 00 00 00 42 65 74 74 79 00 00 00 00 00 00 00 >....Betty.......<
    000070 00 00 00 00 00 00 00 00 00 08 40 00 00 00 00 00 >..........@.....<
    000080
    The blue number is the .pay member, which shows that person.pay = 1 happened.
    The red number is person.flag, which is set up in main.

    Because there is at least ONE record where .pay is zero, this happens
    Code:
        if(payment.pay==0){
          chec=0;
          break;
        }
    Which means this NEVER happens
    Code:
      if(chec==1){
    Sir, please be a little polite (i am 14 years, and not a coding expert)
    and, the i have written "
    Code:
        if(payment.pay==0){
          chec=0;
          break;
        }
    "
    because, this should reset all the payment flags, to 0 when everyone has given the payment. So that the program is ready to accept the next set of payments in the coming month
    Therefore it should reset all the flags only when everyone has given the payment
    Daksh
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0
    Hey Salem, Please reply
  28. #15
  29. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Reply to what?

    I gave you a problem to solve - namely the chec = 0 ... chec == 1 issue.

    Until you post an attempt at solving it, I can't say anything more about it.
    And I'm certainly not going to put effort into solving it for you.
    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
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo