Thread: How do you search & sort an array?

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

    How do you search & sort an array?

    I have two files and I would like to seach them and sort them in any order. My two data files are cust.dat and order.dat.
    Code:
    Cust.dat contains:
    
    CustomerId 
    CustomerFirstName
    CustomerMiddleName
    CustomerLastName
    CustomerAddress
    CityStateZip
    CustomerPhoneNo
    CustomerEmailAddress
    
    order.dat contains:
    
    orderId
    width
    length
    CarpetCharge
    discount
    
    
    
    int NotFound = 0;
    While((k < NUM_OF_CUSTOMERS) && (NotFound ==1))
       {
         if ( searchKey ==custRec[key]customerId)
           {
             NotFound = 0;
           }
         if ( searchKey ==orderRec[key]orderId)
           {
             NotFound = 0;
           }
            K++;
        }
    How would I go about sorting it into the fields say CustomerFirstName or by TotalBill?
    Thanks for any help you can provide.
    Imagination at Work

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:27 AM.

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

    re: comparing strings

    I am trying to print out a report sorted by CustomerfirstName, CustomerMiddleName, CustomerLastName
    and another report sorted by TotalBill (two totally seperate reports).

    I have figured out how to read in and sort two data files but my problem is how to sort these two data files and produce the two different reports. Maybe I am making too much of this.

    Thanks.
    Imagination at Work

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:27 AM.

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

    Re: They are sorted?

    I'll try explaining it in a different way.

    At the moment they are sorted by CustomerId and orderId (123456789 23156781 34567890) but if I am to sort the data by the CustomerFirstName or by total the way that I have sorted it would not be right that is by total because the lowest to the highest total would need to be printed.
    The same way with CustomerFirstName it would need to be sorted abc not bac.

    This is what is confusing me.
    I hope I have explained what I am trying to say better.

    Thanks.
    Imagination at Work

  6. #6
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:26 AM.

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

    Re: based on more than one criteria?

    Yes, I belive you understand what I am trying to accomplish.

    So, I think that I would need a search to pull it off. I'm just not sure how to do it.
    Imagination at Work

  8. #8
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:26 AM.

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

    Re: I need to see more.

    It's a lot of code:

    Here is cust.dat:

    Code:
    //This one long record and this an example of what one record would look like
    
    213416576 James    Jimmy     Willey      1234 Easy Street          Rosewell GA 30000         (770)678-1342   [email protected]
    
    order.dat
    //This record coinsides with cust.dat
    213416576 20 10 10 0.20
    
    
    Here's the code:
    
    #include <stdio.h>
    #include <string.h>
    #include "customer.h"
    #include "order.h"
    struct CUST_INFO
    {
    	char CustomerId[CUSTOMER_ID];
    	char CustomerFirstName[FIRST_NAME];
    	char CustomerMiddleName[MIDDLE_NAME];
    	char CustomerLastName[LAST_NAME];
        char CustomerAddress[ADDRESS_SIZE];
    	char CityStateZip[CITY_STATE_ZIP_SIZE];
    	char CustomerPhoneNo[PHONENO_SIZE];
    	char CustomerEmailAddress[EMAIL_ADDRESS];
    };
    struct ORDER_INFO
    {
    	char orderId[ORDER_ID];
    	int length;
    	int width;
    	int carpetCharge;
    	float discount;
    };
    int initialization(struct CUST_INFO custRecs[LIMIT_SIZE], //int *pageNo,
    				   FILE * custFilePtr, struct ORDER_INFO orderRecs[LIMIT_SIZE],
    				   FILE * orderFilePtr, FILE * processFilePtr,
    				   int *pageNo);
    int initializeOrderRec(struct ORDER_INFO orderRecs[LIMIT_SIZE], int *pageNo,
    				   FILE * orderFilePtr, FILE * processFilePtr);
    void calculateInvoice(struct CUST_INFO custrecs[LIMIT_SIZE], struct ORDER_INFO orderRecs[LIMIT_SIZE], int *pageNo,
    					  int howMany, FILE * processFilePtr,
    					  FILE * summaryFilePtr);
    void PrintHeadings(int *pageNo, FILE * processFilePtr);
    void GetTopLine(FILE * processFilePtr);
    void HorizontalLine(FILE * processFilePtr);                                                 
    void GetBottomLine(FILE * processFilePtr);
    void processCustomerRecord(char CustomerId[LIMIT_SIZE],
    						   char CustomerFirstName[LIMIT_SIZE],
                               char CustomerMiddleName[LIMIT_SIZE],
    						   char CustomerLastName[LIMIT_SIZE],
    						   char CustomerAddress[LIMIT_SIZE],
    						   char CityStateZip[LIMIT_SIZE],
    						   char CustomerPhoneNo[LIMIT_SIZE],
    						   char CustomerEmailAddress[LIMIT_SIZE],
    						   char orderId[LIMIT_SIZE],
    						   int length, int width, int area,
    						   int carpetCharge,
    						   int carpetChargeTotal, float laborCost,
    						   float installPrice, float discount,
    						   float discountTotal,
    						   float subTotal,  float tax, 
    						   float total, int *pageNo, int howMany,
    						   FILE * processFilePtr);
    void sortCustomerRecord(struct CUST_INFO custRecs[LIMIT_SIZE], struct ORDER_INFO orderRecs[LIMIT_SIZE],
    						int *pageNo, int howMany);
    void PrintSummaryHeadings(FILE * summaryFilePtr);
    void GetSummaryTopLine(FILE * summaryFilePtr);
    void HorizontalSummaryLine(FILE * summaryFilePtr);
    void GetSummaryBottomLine(FILE * processFilePtr);
    void summaryProcessCustomerRecord(char CustomerId[LIMIT_SIZE],
    						   char CustomerFirstName[LIMIT_SIZE],
                               char CustomerMiddleName[LIMIT_SIZE],
    						   char CustomerLastName[LIMIT_SIZE],
    						   char CustomerAddress[LIMIT_SIZE],
    						   char CityStateZip[LIMIT_SIZE],
    						   char CustomerPhoneNo[LIMIT_SIZE],
    						   char CustomerEmailAddress[LIMIT_SIZE],
    						   char orderId[LIMIT_SIZE],
    						   int length, int width, int area,
    						   int carpetCharge,
    						   int carpetChargeTotal, float laborCost,
    						   float installPrice, float discount,
    						   float discountTotal,
    						   float subTotal,  float tax, 
    						   float total, int *pageNo, int howMany,
    						   FILE * summaryFilePtr);
    int calculateLengthWidth(int *length, int *width);
    int calculateCarpetCharge(int *carpetCharge, int *area);
    float calculateLaborCost(int area);
    float calculateInstallPrice(int carpetChargeTotal, float laborCost);
    float calculateDiscount( float installPrice, float discount);
    float calculateSubtotal(float installPrice, float discountTotal);
    float calculateTax(float subTotal);
    float calculateTotal(float tax, float subTotal);
    void main(int argc, char * argv[])
    {
    	char CustomerId[LIMIT_SIZE][CUSTOMER_ID] = {0};
    	char CustomerFirstName[LIMIT_SIZE][FIRST_NAME] = {0};
    	char CustomerMiddleName[LIMIT_SIZE][MIDDLE_NAME]= {0};
    	char CustomerLastName[LIMIT_SIZE][LAST_NAME]= {0};
    	char CustomerAddress[LIMIT_SIZE][ADDRESS_SIZE] = {0};
    	char CityStateZip[LIMIT_SIZE][CITY_STATE_ZIP_SIZE] = {0};
    	char CustomerPhoneNo[LIMIT_SIZE][PHONENO_SIZE] = {0};
    	char CustomerEmailAddress[LIMIT_SIZE][EMAIL_ADDRESS] = {0};
    	char orderId[LIMIT_SIZE][ORDER_ID] = {0};
    	int length[LIMIT_SIZE] = {0};
    	int width[LIMIT_SIZE] = {0};
        int carpetCharge[LIMIT_SIZE] = {0};
    	float discount[LIMIT_SIZE] = {0};
    	static int pageNo = 0;
    	int readStatus = 0;
    	int howMany = 0;
    	FILE * custFilePtr;
    	FILE * orderFilePtr;
    	FILE * processFilePtr;
    	FILE * summaryFilePtr;
    	struct CUST_INFO custRecs[LIMIT_SIZE];
    	struct ORDER_INFO orderRecs[LIMIT_SIZE];
    	if(argc < 5)
    	{
    		printf("Usage: %s {input file} {output file}\n",
    			argv[0]);
    		return;
    	}//end if
    	custFilePtr = fopen(argv[1], "r");
    	if(NULL == custFilePtr)
    	{
    		printf("%s cannot open\"%s\" for input\n", argv[0], argv[1]);
    			return;
    	}//end if
    	orderFilePtr = fopen(argv[2], "r");
    	if(NULL == custFilePtr)
    	{
    		printf("%s cannot open\"%s\" for input\n", argv[0], argv[2]);
    			return;
    	}//end if
    
    	processFilePtr = fopen(argv[3], "w");
    	if(NULL == processFilePtr)
    	{
    		printf("%s cannot open\"%s\" for output\n", argv[0], argv[3]);
    			return;
    	}//end if
    	summaryFilePtr = fopen(argv[4], "w");
    	if(NULL == summaryFilePtr)
    	{
    		printf("%s cannot open\"%s\" for output\n", argv[0], argv[4]);
    			return;
    	}//end if
    	memset(custRecs, 0, sizeof(struct CUST_INFO) * LIMIT_SIZE);
    	memset(orderRecs, 0, sizeof(struct ORDER_INFO) * LIMIT_SIZE);
        howMany = initialization(custRecs, processFilePtr, orderRecs, orderFilePtr, processFilePtr,
    		&pageNo);
    	calculateInvoice( custRecs, orderRecs, &pageNo, howMany, processFilePtr, summaryFilePtr);
    	sortCustomerRecord(custRecs, orderRecs, &pageNo, howMany);
    	calculateInvoice(custRecs, orderRecs, &pageNo, howMany, processFilePtr, summaryFilePtr);
    	return;
    }//End Main
    // Load table
    int initialization(struct CUST_INFO custRecs[LIMIT_SIZE],
    				   FILE * custFilePtr, struct ORDER_INFO orderRecs[LIMIT_SIZE],
    				   FILE * orderFilePtr, FILE * processFilePtr, int *pageNo)
    {
    	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);
    	}
    	
    	while ((k < LIMIT_SIZE) && (fgets(inputBuffer, 1024,
    			orderFilePtr)!= NULL))
    		{
    		sscanf(inputBuffer, "%25c %i %i %i %f\n",
    			orderRecs[k].orderId, &orderRecs[k].width, &orderRecs[k].length,
    			&orderRecs[k].carpetCharge,
    			&orderRecs[k].discount);
    		printf("Read All Records");
    		k++;
    		
    		}//end while loop
    	if(k == 0)
    	{
    	
    	printf("Read All Records 1\n");
    	}
    	GetTopLine(processFilePtr);
    	PrintHeadings(pageNo, processFilePtr);
    	printf("k = : %d \n", k);
    	return k;
    }//end initialization
    void GetTopLine(FILE * processFilePtr)
    {
    	int tLine = 0;
    	fprintf(processFilePtr, "%c", 218);
    	for(tLine = 0; tLine < 78; tLine++)
    	{
    		fprintf(processFilePtr, "%c", 196);
    	}//end for loop
    	fprintf(processFilePtr, "%c\n", 191);
    }//End GetTopLine
    void HorizontalLine(FILE * processFilePtr)
    {
    	int hLine = 0;
    	for(hLine = 0; hLine < 78; hLine++)
    	{
    		fprintf(processFilePtr, "%c", 196);
    	}//end for loop
    }//End HorizontalLine
    void GetBottomLine(FILE * processFilePtr)
    {
    	int bLine = 0;
    	fprintf(processFilePtr, "%c", 192);
    	for(bLine = 0; bLine < 78; bLine++)
    	{
    		fprintf(processFilePtr, "%c", 196);
    	}//end for loop
    	fprintf(processFilePtr, "%c", 217);
    }//End GetBottomLine
    void PrintHeadings(int *pageNo, FILE * processFilePtr)
    {   
    	(*pageNo)++;
    	fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "Program Name: PA18.exe");
    	fprintf(processFilePtr, "%15s By Tommy Hicks %10s", "", "");
    	fprintf(processFilePtr, "Page No %3i %3s", *pageNo, "");
    	fprintf(processFilePtr, "%c\n", 179);
    	fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "Run Date: 10/22/2001 %57s", "");
    	fprintf(processFilePtr, "%c\n", 179);
    	fprintf(processFilePtr, "%c", 195);
        HorizontalLine(processFilePtr);
    	fprintf(processFilePtr, "%c\n", 180);
    }//End PrintHeadings
    void calculateInvoice(struct CUST_INFO custRecs[LIMIT_SIZE],
    					  struct ORDER_INFO orderRecs[LIMIT_SIZE],
    					  int *pageNo, int howMany, FILE * processFilePtr,
    					  FILE * summaryFilePtr)
    {
    	//int x;
    	int area = 0;
    	int carpetChargeTotal = 0;
    	float laborCost = 0;
    	float installPrice = 0;
    	float subTotal = 0;
    	float discountTotal = 0;
    	float tax = 0;
    	float total= 0;
    	static int x = 0;
    		for(x=0; x < howMany; x++)
    			{
    			area = calculateLengthWidth(&orderRecs[x].length, &orderRecs[x].width);
    	        carpetChargeTotal = calculateCarpetCharge(&orderRecs[x].carpetCharge,
    				&area);
    	        laborCost = calculateLaborCost(area);
    	        installPrice = calculateInstallPrice(carpetChargeTotal, laborCost);
    	        discountTotal = calculateDiscount(installPrice, orderRecs[x].discount);
    		    processCustomerRecord(orderRecs[x].orderId,
    				custRecs[x].CustomerFirstName, custRecs[x].CustomerMiddleName,
    				custRecs[x].CustomerLastName, custRecs[x].CustomerAddress,
    				custRecs[x].CityStateZip, custRecs[x].CustomerPhoneNo,
    				custRecs[x].CustomerEmailAddress, orderRecs[x].orderId,
    			    orderRecs[x].length, 
    				orderRecs[x].width, area, orderRecs[x].carpetCharge,
    				carpetChargeTotal, laborCost, installPrice,
    				orderRecs[x].discount, discountTotal, subTotal, tax, total,
    				pageNo, howMany, processFilePtr);
    
    		}//end for loop
    		PrintSummaryHeadings(summaryFilePtr);
    		for(x=0; x < howMany; x++)
    			{
    			area = calculateLengthWidth(&orderRecs[x].length,
    				&orderRecs[x].width);
    	        carpetChargeTotal = calculateCarpetCharge(&orderRecs[x].carpetCharge,
    				&area);
    	        laborCost = calculateLaborCost(area);
    	        installPrice = calculateInstallPrice(carpetChargeTotal,
    				laborCost);
    	        discountTotal = calculateDiscount(installPrice,
    				orderRecs[x].discount);
                summaryProcessCustomerRecord(
    				custRecs[x].CustomerId,
    				custRecs[x].CustomerFirstName, custRecs[x].CustomerMiddleName,
    				custRecs[x].CustomerLastName, custRecs[x].CustomerAddress,
    				custRecs[x].CityStateZip, custRecs[x].CustomerPhoneNo,
    				custRecs[x].CustomerEmailAddress, orderRecs[x].orderId,
    				orderRecs[x].length, 
    				orderRecs[x].width, area, orderRecs[x].carpetCharge,
    				carpetChargeTotal, laborCost, installPrice,
    				orderRecs[x].discount, discountTotal, subTotal, tax, total,
    				pageNo, howMany, summaryFilePtr);
    		}//end for loop
    		GetBottomLine(summaryFilePtr);
    		return;
    }//end calculateInvoice
    void processCustomerRecord(char CustomerId[LIMIT_SIZE],
    						   char CustomerFirstName[LIMIT_SIZE],
    						   char CustomerMiddleName[LIMIT_SIZE],
    						   char CustomerLastName[LIMIT_SIZE],
    						   char CustomerAddress[LIMIT_SIZE],
    						   char CityStateZip[LIMIT_SIZE],
    						   char CustomerPhoneNo[LIMIT_SIZE],
    						   char CustomerEmailAddress[LIMIT_SIZE],
    						   char orderId[LIMIT_SIZE],
    						   int length, int width, int area,
    						   int carpetCharge, int carpetChargeTotal,
    						   float laborCost, float installPrice,
    						   float discount, float discountTotal,  
    						   float subTotal,  float tax, float total,
    						   int *pageNo, int howMany, FILE * processFilePtr)
    {
    	int k = 0; 
    	int pageCounter = 0;
        fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "Customer Id:  %9s %53s %c\n", CustomerId, "", 179);
    	fprintf(processFilePtr, "Order Id:  %9s %53s %c\n", orderId, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%cFirst Name:   %10s %53s%c\n", 179, CustomerFirstName, "", 179);
    	fprintf(processFilePtr, "%cMiddle Name:  %10s %53s%c\n", 179, CustomerMiddleName, "", 179);
    	fprintf(processFilePtr, "%cLast Name:    %10s %52s %c\n", 179, CustomerLastName, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%cAddress:      %25s %37s %c\n", 179, CustomerAddress,
    		"", 179);
    	fprintf(processFilePtr, "%c              %25s %37s %c\n", 179, CityStateZip,
    		"", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%cPhone No:       %15s %45s %c\n", 179, CustomerPhoneNo,
    		"", 179);
    	fprintf(processFilePtr, "%cEmail Address:  %25s %35s %c\n", 179, CustomerEmailAddress,
    		"", 179);
    	fprintf(processFilePtr, "%c", 195);
    	HorizontalLine(processFilePtr);
    	fprintf(processFilePtr, "%c\n", 180);
    	fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "%37s MEASUREMENT %28s", "", "");
    	fprintf(processFilePtr, "%c\n", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %25s Length %20s %d ft %16s %c\n",
    		179, "",  "", length, "", 179);
    	fprintf(processFilePtr, "%c %25s Width %21s %d ft %16s %c\n",
    		179, "",  "", width, "", 179);
    	fprintf(processFilePtr, "%c %25s Area %21s %d ft %16s %c\n",
    		179, "",  "", area, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "%37s CHARGES %32s", "", "");
    	fprintf(processFilePtr, "%c\n", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c", 179);
    	fprintf(processFilePtr, "%25S DESCRIPTION  COST/SQ.FT.  CHARGE/ROOM %14s", "", "");
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %24s ___________  ___________  ___________ %13s %c\n", 179, "", "", 179);
        fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %25s Carpet         %d            %d %17s%c\n", 179, "", carpetCharge, 
    		carpetChargeTotal, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %25s Labor         .35 %8s   $%03.2f   %12s %c\n", 179, "", "", laborCost, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %48s   ___________ %13s %c\n", 179, "", "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %25s INSTALLED PRICE           $%03.2f   %13s %c\n", 179, "",
    		installPrice, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %25s Discount %3s %03.2f%% %8s %6.2f %15s %c\n",
    		179, "", "", discount, "", discountTotal, "", 179);
        fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %48s   ___________ %13s %c\n",
    		179, "", "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	subTotal = installPrice - discountTotal;
    	fprintf(processFilePtr, "%c %25s SUBTOTAL %7s          $%7.2f   %13s %c\n", 179, "", "",
    		subTotal, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	tax = subTotal * TAX_AMT;
        fprintf(processFilePtr, "%c %25s Tax %12s          $%6.2f   %14s %c\n", 179, "", "",
    		tax, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	total = subTotal + tax;
    	fprintf(processFilePtr, "%c %25s TOTAL %10s          $%03.2f   %13s %c\n", 179, "", "",
    		total, "", 179);
    	fprintf(processFilePtr, "%c %76s %c\n", 179, "", 179);
    	GetBottomLine(processFilePtr);
    	fprintf(processFilePtr, "\f\n\n");
    	if(*pageNo < PAGE_LIMIT)
    	{
    		pageCounter++;
            GetTopLine(processFilePtr);
    	    PrintHeadings(pageNo, processFilePtr);
    	}//end if
    	return;
    }//End ProcessCustomerRecord
    void sortCustomerRecord(struct CUST_INFO custRecs[LIMIT_SIZE],
    						struct ORDER_INFO orderRecs[LIMIT_SIZE],
    						int *pageNo, int howMany)
    {
    	int k;
    	int status = 0;
    	char tempId[9] = {0};
    	char tempFirstName[10] = {0};
    	char tempMiddleName[10] = {0};
    	char tempLastName[10] = {0};
    	char tempAddress[26] = {0};
    	char tempCityStateZip[26] = {0};
    	char tempPhoneNo[16] = {0};
    	char tempEmailAddress[9] = {0};
    	char tempOrderId[9] = {0};
    	int tempLength = 0;
    	int tempWidth = 0;
    	int tempCarpetCharge = 0;
    	float tempDiscount = 0;
    	int morePasses = 1;//switch loop on
    	while(morePasses == 1)
    	{
    		morePasses = 0;//switch loop off
    		for(k=0; k < howMany - 1; k++)
    		{
    			if(strcmp (custRecs[k].CustomerId,
    				custRecs[k+1].CustomerId) && (strcmp (orderRecs[k].orderId,
    				orderRecs[k+1].orderId)> 0))
    			{
                    strcpy(tempId, custRecs[k].CustomerId);
    				strcpy(custRecs[k].CustomerId, custRecs[k+1].CustomerId);
    				strcpy(custRecs[k+1].CustomerId, tempId);
    
                    strcpy(tempFirstName, custRecs[k].CustomerFirstName);
    				strcpy(custRecs[k].CustomerFirstName, custRecs[k+1].CustomerFirstName);
    				strcpy(custRecs[k+1].CustomerFirstName, tempFirstName);
    
    				strcpy(tempMiddleName, custRecs[k].CustomerMiddleName);
    				strcpy(custRecs[k].CustomerMiddleName, custRecs[k+1].CustomerMiddleName);
    				strcpy(custRecs[k+1].CustomerMiddleName, tempMiddleName);
    
    				strcpy(tempLastName, custRecs[k].CustomerLastName);
    				strcpy(custRecs[k].CustomerLastName, custRecs[k+1].CustomerLastName);
    				strcpy(custRecs[k+1].CustomerLastName, tempLastName);
    
                    strcpy(tempAddress, custRecs[k].CustomerAddress);
    				strcpy(custRecs[k].CustomerAddress, custRecs[k+1].CustomerAddress);
    				strcpy(custRecs[k+1].CustomerAddress, tempAddress);
    
    				strcpy(tempCityStateZip, custRecs[k].CityStateZip);
    				strcpy(custRecs[k].CityStateZip, custRecs[k+1].CityStateZip);
    				strcpy(custRecs[k+1].CityStateZip, tempCityStateZip);
    
    				strcpy(tempPhoneNo, custRecs[k].CustomerPhoneNo);
    				strcpy(custRecs[k].CustomerPhoneNo, custRecs[k+1].CustomerPhoneNo);
    				strcpy(custRecs[k+1].CustomerPhoneNo, tempPhoneNo);
    
    				strcpy(tempEmailAddress, custRecs[k].CustomerEmailAddress);
    				strcpy(custRecs[k].CustomerEmailAddress, custRecs[k+1].CustomerEmailAddress);
    				strcpy(custRecs[k+1].CustomerEmailAddress, tempEmailAddress);
    
                    strcpy(tempId, orderRecs[k].orderId);
    				strcpy(orderRecs[k].orderId, orderRecs[k+1].orderId);
    				strcpy(orderRecs[k+1].orderId, tempOrderId);
    
                    tempLength = orderRecs[k].length;
    				orderRecs[k].length =orderRecs[k+1].length;
    				orderRecs[k+1].length = tempLength;
    
    				tempWidth =orderRecs[k].width;
    				orderRecs[k].width =orderRecs[k+1].width;
    				orderRecs[k+1].width = tempWidth;
    
    				tempCarpetCharge = orderRecs[k].carpetCharge;
    				orderRecs[k].carpetCharge =orderRecs[k+1].carpetCharge;
    				orderRecs[k+1].carpetCharge = tempCarpetCharge;
    
    				tempDiscount =orderRecs[k].discount;
    				orderRecs[k].discount =orderRecs[k+1].discount;
    				orderRecs[k+1].discount = tempDiscount;
    				morePasses = 1;
    			}//end if
    		}//end for loop
    	}//end while loop
    	return; //status;
    }//end sortCustomerRecord
    void GetSummaryTopLine(FILE * summaryFilePtr)
    {
    	int tLine = 0;
    	fprintf(summaryFilePtr, "%c", 218);
    	for(tLine = 0; tLine < 78; tLine++)
    	{
    		fprintf(summaryFilePtr, "%c", 196);
    	}//end for loop
    	fprintf(summaryFilePtr, "%c\n", 191);
    }//End GetSummaryTopLine
    void HorizontalSummaryLine(FILE * summaryFilePtr)
    {
    	int hLine = 0;
    	for(hLine = 0; hLine < 78; hLine++)
    	{
    		fprintf(summaryFilePtr, "%c", 196);
    	}//end for loop
    }//End HorizontalSummaryLine
    void GetBottomSummaryLine(FILE * summaryFilePtr)
    {
    	int bLine = 0;
    	fprintf(summaryFilePtr, "%c", 192);
    	for(bLine = 0; bLine < 78; bLine++)
    	{
    		fprintf(summaryFilePtr, "%c", 196);
    	}//end for loop
    	fprintf(summaryFilePtr, "%c", 217);
    }//End GetBottomLine
    void PrintSummaryHeadings(FILE * summaryFilePtr)
    {   
    	static int pageNo = 0;
    	fprintf(summaryFilePtr, "\f\n");
    	pageNo++;
    	GetSummaryTopLine(summaryFilePtr);
    	fprintf(summaryFilePtr, "%c", 179);
    	fprintf(summaryFilePtr, "Program Name: PA18.exe");
    	fprintf(summaryFilePtr, "%15s By Tommy Hicks %10s", "", "");
    	fprintf(summaryFilePtr, "Page No %3i %3s", pageNo, "");
    	fprintf(summaryFilePtr, "%c\n", 179);
    	fprintf(summaryFilePtr, "%c", 179);
    	fprintf(summaryFilePtr, "Run Date: 10/22/2001 %57s", "");
    	fprintf(summaryFilePtr, "%c\n", 179);
    	fprintf(summaryFilePtr, "%c", 195);
        HorizontalSummaryLine(summaryFilePtr);
    	fprintf(summaryFilePtr, "%c\n", 180);
    }//End PrintHeadings
    void summaryProcessCustomerRecord(char CustomerId[LIMIT_SIZE],
    								  char CustomerFirstName[LIMIT_SIZE],
    								  char CustomerMiddleName[LIMIT_SIZE],
    								  char CustomerLastName[LIMIT_SIZE],
    						          char CustomerAddress[LIMIT_SIZE],
    						          char CityStateZip[LIMIT_SIZE],
    						          char CustomerPhoneNo[LIMIT_SIZE],
    								  char CustomerEmailAddress[LIMIT_SIZE],
    								  char orderId[LIMIT_SIZE],
    						          int length, int width, int area, int carpetCharge,
    						          int carpetChargeTotal, float laborCost,
    						          float installPrice, float discount, float discountTotal,
    						          float subTotal,  float tax, 
    						          float total, int *pageNo, int howMany,
    						          FILE * summaryFilePtr)
    {
    	int k = 0; 
    	static int lineCounter = 0;
    	lineCounter++;
        fprintf(summaryFilePtr, "%c", 179);
    	fprintf(summaryFilePtr, "First Name:   %10s %52s %c\n", CustomerFirstName, "", 179);
    	fprintf(summaryFilePtr, "%cMiddle Name:  %10s %52s %c\n",
    		179, CustomerMiddleName, "", 179);
    	fprintf(summaryFilePtr, "%cLast Name:    %10s %52s %c\n", 179, CustomerLastName, "", 179);
    	fprintf(summaryFilePtr, "%c %76s %c\n", 179, "", 179);
    	subTotal = installPrice - discountTotal;
    	tax = subTotal * TAX_AMT;
        total = subTotal + tax;
    	fprintf(summaryFilePtr, "%c %25s TOTAL %10s          $%03.2f   %13s %c\n", 179, "", "",
    		total, "", 179);
    	fprintf(summaryFilePtr, "%c %76s %c\n", 179, "", 179);
    	if(*pageNo >  PAGE_LIMIT)
    	{
    	   GetBottomLine(summaryFilePtr);
           GetSummaryTopLine(summaryFilePtr);
    	   PrintSummaryHeadings(summaryFilePtr);
    	}//end if
    	
    
    	return;
    }//End summaryProcessCustomerRecord
    int calculateLengthWidth(int *length, int *width)
    {
    	int area = *length * *width;
    	return area;
    }//End calculateLengthWidth
    int calculateCarpetCharge(int *carpetCharge, int *area)
    {
    	int carpetChargeTotal = *carpetCharge * *area;
    	return carpetChargeTotal;
    }//end calculateCarpetCharge
    float calculateLaborCost( int area)
    {
    	return area * LABOR_COST;
    }// end calculateCarpetCharge
    float calculateInstallPrice(int carpetChargeTotal, float laborCost)
    {
    	return carpetChargeTotal + laborCost;
    }// end calculateInstallPrice
    float calculateDiscount( float installPrice,  float discount)
    {
    	return  discount * installPrice;
    }// end calculateDiscount
    
    ------------------------------------------------------------------------------------
    
    Now, I have to produce a Customer Listing sorted by CustomerName (first, middle,last).
    A listing sorted by the total
    A history report sorted by CustomerName(first, middle, last)
    A history report sorted by the total
    
    ------------------------------------------------------------------------------------
    
    This is what I have been working on all week and I am stuck on how to do this.
    Imagination at Work

  10. #10
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:26 AM.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Holy christ! There is a reason you can add attachments. This is so I don't have to page through twenty five "page down"s of text because someone decided to post their entire fifteen file project!

    Quzah.

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

    Re: Need more data files

    Here are the data files that you requested:

    Code:
    cust.dat
    
    123456789 Thomas    Hurton    Hicks     5990 Meadow Crest Way     Cumming GA 30040          (777)711-5002   [email protected] Rosh      Names     Bilt      1234 Easy Street          Rosewell GA 30000         (670)678-1342   [email protected]
    314123765 rick      William   Reno      6756 Dulth Hwy            Duluth GA 30222           (578)563-2080   [email protected]
    
    order.dat
    
    123456789 20 10 10 0.20
    213416576 10 10 10 0.05
    314123765 10 20 10 0.10
    Thanks for all of your help!!!!
    Last edited by sketchit; 11-01-2001 at 09:21 PM.
    Imagination at Work

  13. #13
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:25 AM.

  14. #14
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:25 AM.

  15. #15
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 12-01-2001 at 10:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. How to sort an array of pointers to structure
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 06-30-2008, 02:52 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM