Thread: I don't understand!

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    35

    I don't understand!

    This program is suppose to read in two files and print 2 reports, sorted and unsorted.

    All it does is print the headings for the sorted.

    Here is the part that I suspect is wrong:
    Code:
    include "customer.h"
    
    contains:
    
    #define CUSTOMER_ID          10
    #define FIRST_NAME           11
    #define MIDDLE_NAME          11
    #define LAST_NAME            11
    #define ADDRESS_SIZE         26
    #define CITY_STATE_ZIP_SIZE  26
    #define PHONENO_SIZE         16
    #define EMAIL_ADDRESS        26
    #define LABOR_COST          .35f
    #define TAX_AMT             .085f
    #define PAGE_LIMIT           6
    #define SUMMARY_LIMIT        2
    #define LIMIT_SIZE           1000
    
    and
    include "order.h" contains:
    
    #define ORDER_ID      10
    
    The part that I think is wrong:
    
    int initialization(struct CUST_INFO custRecs[LIMIT_SIZE], int *pageNo, FILE * custFilePtr, struct ORDER_INFO orderRecs[LIMIT_SIZE], FILE * orderFilePtr, FILE * processFilePtr)
    {
        int k = 0;
        char inputBuffer[1024] = {0};
        while ((k < LIMIT_SIZE) && (fgets(inputBuffer, 1024,
    	custFilePtr) != NULL))
        {
           sscanf(inputBuffer, "%9c %10c %10c %10c %25c %25c 
                %15c\n", custRecs[k].CustomerId, custRecs
                 [k].CustomerFirstName, 
                 custRecs[k].CustomerMiddleName,
                 custRecs[k].CustomerLastName, 
                 custRecs[k].CustomerAddress, custRecs[k].CityStateZip,
                 custRecs[k].CustomerPhoneNo, 
                 custRecs[k].CustomerEmailAddress);
         }//end while loop
         while (( k < LIMIT_SIZE) && (fgets(inputBuffer, 1024, 
                orderFilePtr) != NULL))
         {
         sscanf(inputBuffer, "%9c %25c %i %i %i %f\n",
    	orderRecs[k].orderId, &orderRecs[k].width,
                   &orderRecs[k].length,
                   &orderRecs[k].carpetCharge, &orderRecs[k].discount);
    	k++;
         }//end while loop
         GetTopLine(processFilePtr);
         PrintHeadings(pageNo, processFilePtr);
         return k;
    	
    }//end initialization
    Imagination at Work

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Code:
        while ((k < LIMIT_SIZE) && (fgets(inputBuffer, 1024,
    	custFilePtr) != NULL))
        {
           sscanf(inputBuffer, "%9c %10c %10c %10c %25c %25c 
                %15c\n", custRecs[k].CustomerId, custRecs
                 [k].CustomerFirstName, 
                 custRecs[k].CustomerMiddleName,
                 custRecs[k].CustomerLastName, 
                 custRecs[k].CustomerAddress, custRecs[k].CityStateZip,
                 custRecs[k].CustomerPhoneNo, 
                 custRecs[k].CustomerEmailAddress);
         }//end while loop
    Okay this loop will probably only get the last record. Maybe you want to increment k or something.
    Last edited by Troll_King; 11-01-2001 at 04:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 10-14-2006, 04:38 AM
  2. Need software to help to understand C source code
    By Kincider in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2006, 09:44 PM
  3. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  4. Need help to understand x["AC"] in the following code
    By jcourcel in forum C Programming
    Replies: 11
    Last Post: 06-06-2006, 01:13 AM
  5. I don't understand K&R example
    By rllovera in forum C Programming
    Replies: 8
    Last Post: 10-25-2004, 10:45 AM