Thread: Can't pass array to function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    Can't pass array to function

    In this exercise there are 4 sales people and 5 products. I'm supposed to figure out how much of each product each sales person sold in a month. initSales randomly generates the sales into transaction[][][] and succeeds in doing so. The problem I'm having is with totalSales which is supposed to total all the sales for a month for every product a person sold in a month. Whenever I try to compile the program I get,

    6.22.c: In function `main':
    6.22.c:23: warning: passing arg 1 of `totalSales' from incompatible pointer type
    6.22.c:23: warning: passing arg 2 of `totalSales' from incompatible pointer type

    What am I doing wrong?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define PERSON 5
    #define PRODUCT 6
    #define DAY 31
    
    void initSales( int [][][] );
    void totalSales( int [][], int [][][] );
    
    
    
    
    int main()
    {
       int transaction[ PERSON ][ PRODUCT ][ DAY ] = { 0 };
       int sales[ PERSON ][ PRODUCT ] = { 0 };
    
       srand( time(NULL) );
    
       initSales( transaction );
       totalSales( transaction, sales );
    
    
       return 0;
    }
    
    
    
    
    
    void initSales(int var[][ PRODUCT ][ DAY ])
    {
       int i, j, k;
    
    
       for (i = 1; i <= PERSON - 1; ++i) {
          for (j = 1; j <= PRODUCT - 1; ++j) {
             for (k = 1; k <= DAY - 1; ++k) {
                var[i][j][k] = rand() &#37; 1000;
                /* test statement below */
    //          printf("person: %d\nproduct: %d\n day: %d\nsold: %d\n\n", i, j, k, var[i][j][k]);
             }
          }
       }
    
    return;
    }
    
    
    
    
    
    void totalSales( int sumofSales[][ PRODUCT ], int transactionsMade[][ PRODUCT ][ DAY ] )
    {
       int a, b, c;
    
    
       for (a = 1; a <= PERSON - 1; ++a) {
          for (b = 1; b <= PRODUCT - 1; ++b) {
             for (c = 1; c <= DAY - 1; ++c) {
                sumofSales[ a ][ b ] += transactionsMade[ a ][ b ][ c ];
                /* test statement below */
                printf("person: %d\nproduct: %d\nsold: %d\n\n", a, b, sumofSales[ a ][ b ]);
             }
          }
       }
    
    
    return;
    }
    Last edited by yougene; 08-18-2007 at 11:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Is it possible to pass an array to a function?
    By Loic in forum C++ Programming
    Replies: 20
    Last Post: 05-06-2007, 10:04 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. pass the pointer of a two dimension array to a function
    By SoFarAway in forum C Programming
    Replies: 8
    Last Post: 04-13-2005, 05:43 AM