Error

This is a discussion on Error within the C Programming forums, part of the General Programming Boards category; I'm tryng to set parameters and it doesn't seem to eb workign for array of floats and 3d array of ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Angry Error

    I'm tryng to set parameters and it doesn't seem to eb workign for array of floats and 3d array of characters...here's some of the program:

    init(&n, products[100], unit[100], amount[100], optimal[100])

    void init(int *n, char *products[100][MAXLENGTH], char *unit[100][MAXLENGTH], float *amount[100], float *optimal[100])
    {
    int count, num;
    char product[100][MAXLENGTH], units[100][MAXLENGTH];

    printf("How many different products at optimal level can fit into your Fridge?\n");
    scanf("%d", &num);

    printf("Please select your products, their optimal level and");
    printf(" their unit.\nie milk x litres, apple x none:\n");
    for(count=0;count < num; count ++)
    {
    scanf("%s %f %s", product, &optimal[count], units);
    amount[count] = optimal[count];
    strcpy(*products[count],product);
    strcpy(*unit[count], units);
    }
    printf("To begin, we assume that the fridge is fully stocked\n");
    *n = num;
    }

    it doesn't seem to eb workinf\g...can I send arrays as parameters??

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: Error

    Originally posted by izimmer

    init(&n, products[100], unit[100], amount[100], optimal[100])
    Well, you can pass array's as parameters. I assume this code is in your main function? You don't clearly state that in your original post so I can only assume. Anyway, when you pass something you don't have to put the subscript after the name (i.e. products[100]) simply call the function like this.

    init( &n, products, unit, amount, optimal );

    Hope this helps. Your code may have other errors but this was the main one I saw.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    Ok I initially did that, but it came up with that I performed an illegal operation during the init stage...so i'll send the whole thing...If someone can help...that'll be great!
    Attached Files Attached Files

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Given
    Code:
        int count, n;
        char products[100][MAXLENGTH];
        char unit[100][MAXLENGTH];
        float amount[100];
        float used[100];
        float optimal[100];
    
        init(&n, products, unit, amount, optimal);
    The prototype for this function is

    void init(int *n, char products[100][MAXLENGTH], char unit[100][MAXLENGTH], float amount[100], float optimal[100]);

    And the function is declared
    void init(int *n, char products[100][MAXLENGTH], char unit[100][MAXLENGTH], float amount[100], float optimal[100]) {
    // your code
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21