I'm having a bit of a problem with my code. The compiler is telling me that my code is making a pointer to an integer without a cast. Now I'm not familiar with what this means so maybe someone could point (pun very intended) me in the right direction. Also any general tips would be much appreciated!
The exact error is:
Homework3.c: In function ‘main’:
Homework3.c:32: warning: passing argument 1 of ‘add’ makes pointer from integer without a cast
Homework3.c:16: note: expected ‘int (*)[5]’ but argument is of type ‘int’
#include <stdio.h>
#include <stdlib.h>
#define INPUT_FILE_NAME "amounts.txt"
#define PRODUCTS 5
#define SALESPERSON 4
#define AMOUNT 1449
#define TOTALS 20
void printOut(int [SALESPERSON][PRODUCTS], float [TOTALS]);
float add(int [SALESPERSON][PRODUCTS], float, float [TOTALS] );
int main(void){
FILE *inputFile;
int sales[SALESPERSON][PRODUCTS];
float data = 0.0;
float totals[TOTALS];
int count;
inputFile = fopen(INPUT_FILE_NAME, "r");
for ( count = 0; count < AMOUNT; count++){
fscanf(inputFile, "%d", sales[SALESPERSON]);
fscanf(inputFile, "%d", sales[SALESPERSON][PRODUCTS]);
fscanf(inputFile, "%f", &data);
add(sales[SALESPERSON][PRODUCTS], data, totals[TOTALS]);
}
fclose(inputFile);
printOut(sales[SALESPERSON][PRODUCTS], totals[TOTALS]);
return 0;
}
void printOut(sales[SALESPERSON][PRODUCTS], totals[TOTALS]){
int count2 = 0;
int count3 = 0;
int count4 = 0;
for(count2 = 0; count2 < SALESPERSON; count2++){
for(count3 = 0; count3 < PRODUCTS; count3++){
printf("Sales Person %d \t Product%d \t Total: %.2f\n", count2, count3, totals[count4]);
++count4;
}
}
return ;
}
void add(sales[SALESPERSON][PRODUCTS], data, totals[TOTALS]){
if(sales[SALESPERSON] == 1){
if(sales[SALESPERSON][PRODUCTS] == 1){
totals[0] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 2){
totals[1] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 3){
totals[2] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 4){
totals[3] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 5){
totals[4] += data;
}
}
else if(sales[SALESPERSON] == 2){
if(sales[SALESPERSON][PRODUCTS] == 1){
totals[5] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 2){
totals[6] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 3){
totals[7] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 4){
totals[8] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 5){
totals[9] += data;
}
}
else if(sales[SALESPERSON] == 3){
if(sales[SALESPERSON][PRODUCTS] == 1){
totals[10] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 2){
totals[11] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 3){
totals[12] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 4){
totals[13] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 5){
totals[14] += data;
}
}
else if(sales[SALESPERSON] == 4){
if(sales[SALESPERSON][PRODUCTS] == 1){
totals[15] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 2){
totals[16] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 3){
totals[17] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 4){
totals[18] += data;
}
else if(sales[SALESPERSON][PRODUCTS] == 5){
totals[19] += data;
}
}
}
addto take the whole array as its first argument, but then you call it passing it only one element (which is also outside the bounds of the array--another problem).