我有我的代碼有點問題。編譯器告訴我,我的代碼在沒有強制轉換的情況下生成一個指向整數的指針。現在我對這意味着什麼都不熟悉,所以也許有人可以指出(打算非常有意)我是朝着正確的方向發展。另外任何一般的提示將非常感謝!使指針整數沒有轉換
確切的錯誤是:
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;
}
}
}
我比這更多的錯誤,當我編譯它。 – 2014-11-21 00:19:23
還有更多的錯誤。我不想讓人們爲我完成我的整個代碼只需要幫助修復這個錯誤haha – TheMadHouse 2014-11-21 00:20:24
你已經定義了'add'來將整個數組作爲它的第一個參數,但是然後你調用它只傳遞一個元素(它也超出了數組的範圍 - 另一個問題)。 – 2014-11-21 00:27:12