I've been playing around with this sorting program and got an error message while compiling it:
"[Warning] passing arg 2 makes integer from pointer without a cast"
The program in question follows:
Code:
/* upBal.c - update balances */
#include <stdio.h>
#include <stdlib.h>
#define MAX_CUSTOMERS 100
struct custRec
{
int ID;
float Bal;
};
/* prototypes of functions */
int readInput(struct custRec *, char *);
void sortData(struct custRec *, int);
void printRecords(struct custRec*, int);
void upDateBalances(struct custRec*, int);
int main()
{
int noOfRecords;
struct custRec custs[MAX_CUSTOMERS];
struct custRec upBal[MAX_CUSTOMERS];
/* read the input */
noOfRecords = readInput(custs, "cust.dat");
noOfRecords = readInput(upBal,"update.dat");
/* sort the both arrays */
sortData(custs,noOfRecords);
sortData(upBal,noOfRecords);
/* update the balances */
upDateBalances(custs,upBal);
/* print the updated values */
printf("Ater updating\n");
printRecords(custs,noOfRecords);
return 0;
}
/* read the input file and put data into the
array that records points at */
int readInput(struct custRec *records, char *fileName)
{
FILE *input = fopen(fileName,"r");
int noOfRecords = 0;
char tempLane[240];
int tempCustId;
float tempCustBal;
if ( input == 0) /* can't open filename */
{
fprintf(stderr,"Can not open %s\n", fileName);
fprintf(stderr,"please check\n\n");
exit(-1);
}
while (fgets(tempLane,240,input))
{
/* if the first character is a "#" ignore */
if (tempLane[0] == '#')
{
continue;
}
/* make sure that the line has 2 numbers */
if (sscanf(tempLane,"%d, %f",
&tempCustId, &tempCustBal) == 2)
{
records[noOfRecords].ID = tempCustId;
records[noOfRecords].Bal = tempCustBal;
noOfRecords++;
}
}
fclose(input);
return noOfRecords;
}
/* sort the records */
void sortData(struct custRec *custs, int noOfRecs)
{
int inner, outer, didSwap;
struct custRec temp;
/* sort the array */
for (outer = 1; outer < noOfRecs; outer++)
{
didSwap = 0;
for (inner = noOfRecs-1; inner >= outer ; inner--)
{
if (custs[inner-1].ID > custs[inner].ID )
{
temp = custs[inner-1];
custs[inner-1] = custs[inner];
custs[inner] = temp;
didSwap = 1;
}
} /* inner loop */
if (didSwap == 0)
{
break;
}
} /* outer loop */
return ;
}
void printRecords(struct custRec* custs, int noOfRecs)
{
int i;
/* print values */
printf("Cust ID Balance\n");
for (i = 0; i < noOfRecs ; i++)
{
printf("%5d %12.2f\n",
custs[i].ID, custs[i].Bal);
}
return;
}
void upDateBalances(struct custRec* custs, struct custRec* newBalances, int noOfRecords)
{
int i;
for (i = 0 ; i < noOfRecords; i++)
{
custs[i].Bal += newBalances[i].Bal;
}
return;
}
I believe that the problem lies in the 'upDateBalances' function because the program will compile when I comment it out as well as its mention within the main program.
The compiling error highlights the piece in the main program
Code:
upDateBalances(custs,upBal);
I'm sure that it's something trivial but yet I cannot seem to see what's wrong. If anyone has any ideas, I'd much appreciate any input. Thanks.