Thread: Loop will not break.

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    69

    Loop will not break.

    I have wriiten some code and I can't seem to figure out why the while the loop will not break. It just keeps looping in both the if statement and else statement. Could someone please help hash out the problem. I have tried modify data and code and have been unable to isolate the problem. Does anyone see the problem? Do you need more of the code?

    Thanks in advance.

    Code:
    *==============================mergeBinFiles=============================
       This function merges two binary files into one.
         Pre: Bin File 1 & Bin File 2
    	 Post: BinOutFile
    */
    void mergeBinFiles(FILE* binFile1, FILE* binFile2, FILE** binOutFile)
    {
      //Local Declarations
          INV_REC itemM1;
          INV_REC itemM2;
          INV_REC sentinel = {9999};
          int mergeCnt = 0;
    		
    //Statements
            printf("\nBegin File Merge:\n");
            fread(&itemM1, sizeof(INV_REC), 1, binFile1);
              if(feof(binFile1))
              itemM1 = sentinel;
           fread(&itemM2, sizeof (INV_REC), 1, binFile2);
              if(feof(binFile2))
              itemM2 = sentinel;
    
          while(!feof(binFile1) || !feof(binFile2))
            {	
            if(strcmp(itemM1.partNo, itemM2.partNo) >= 0)
              {
                fwrite(&itemM2, sizeof(INV_REC), 1, *binOutFile);
    	mergeCnt++;
    	fread(&itemM2, sizeof(INV_REC), 1, binFile2);
    	if(feof(binFile2))
    	  itemM2 = sentinel;
              }//if			 
           else
            {				 
               fwrite(&itemM1, sizeof(INV_REC), 1, *binOutFile);
    	mergeCnt++;
    	fread(&itemM1, sizeof(INV_REC), 1, binFile1);
    	if(feof(binFile1))
    	  itemM1 = sentinel;
            }//else
        }//while
           printf("\nFiles Merged. %d items merged.\n", mergeCnt);
           system("Pause");
           return;
    }//mergeBinFiles
    could someone help please?
    Last edited by silhoutte75; 03-20-2008 at 06:15 PM. Reason: modified question and edited spelling.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Number to Word (Billions)
    By myphilosofi in forum C Programming
    Replies: 34
    Last Post: 02-04-2009, 02:09 AM
  2. Looking for feedback on program segment
    By avron in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 04:38 PM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. Keypress reading
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 12:16 PM
  5. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM