How would you rewrite this???????
I have been working on this program, searched this board and others to try and find out how to rewrite the following code because it doesn't work correctly:
Code:
int initialization(struct CUST_INFO custRecs[LIMIT_SIZE],
FILE * custFilePtr,
struct ORDER_INFO orderRecs[LIMIT_SIZE],
FILE * orderFilePtr, FILE * processFilePtr, int *pageNo);
Code:
howMany = initialization(custRecs, processFilePtr,
orderRecs, orderFilePtr, processFilePtr,
&pageNo);
Code:
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 %25c\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, "%9c %i %i %i %f\n",
&orderRecs[k].orderId,
&orderRecs[k].width,
&orderRecs[k].length,
&orderRecs[k].carpetCharge,
&orderRecs[k].discount);
k++;
}//end while loop
if(k == 0)
{
printf("Read All Records 1\n");
}
GetTopLine(processFilePtr);
PrintHeadings(pageNo, processFilePtr);
return k;
}//end initialization
The above code does not read all of the files
Thanks for any help.
That Made Since but it still does not work.
Salem,
Thanks for the reply. It still is not working after making the changes. It reads in the first record of the first data file(cust.dat) and skips the rest of the files of cust.dat and it now reads all of the second data file (order.dat).
I don't understand why it is doing that.
Here is the code with the corrections that you made:
Code:
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}; // doesn't do you any harm not to do this
k = 0;
while( (k < LIMIT_SIZE) &&
(fgets( inputBuffer, sizeof(inputBuffer), custFilePtr ) != NULL) ) {
sscanf( inputBuffer, "%9c %10c %10c %10c %25c %25c %15c %25c",
&custRecs[k].CustomerId, &custRecs[k].CustomerFirstName,
&custRecs[k].CustomerMiddleName, &custRecs[k].CustomerLastName,
&custRecs[k].CustomerAddress, &custRecs[k].CityStateZip,
&custRecs[k].CustomerPhoneNo, &custRecs[k].CustomerEmailAddress );
k++;
}
k = 0;
while( (k < LIMIT_SIZE) &&
(fgets( inputBuffer, sizeof(inputBuffer), orderFilePtr ) != NULL) ) {
sscanf( inputBuffer, "%9c %i %i %i %f", // no need for \n, this is sscanf
&orderRecs[k].orderId,
&orderRecs[k].width,
&orderRecs[k].length,
&orderRecs[k].carpetCharge,
&orderRecs[k].discount );
k++;
}//end while loop
if(k == 0) {
printf( "Read All Records 1\n" );
}
GetTopLine( processFilePtr );
PrintHeadings( pageNo, processFilePtr );
return k;
}//end initialization
RE: Are these files really text files
Salem:
At the moment, yes they are but once I figure out the problem, I will change all of the "r's" to "rb" and the "w's" to "wb".
Thanks for all of your help but I think this project is useless. :-(