Thread: Passing a pointer to struct array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    68

    Passing a pointer to struct array

    I have a struct
    Code:
    typedef struct
    {
       char *name;
       float value;
       void *pntr;
       uint8_t found;
    }DICTIONARY;
    Initialize it
    Code:
    static DICTIONARY pid_dict[] = 
    {
        {"-p" ,  0, 0, 0 },
        {"-i" ,  0, 0, 0 },
        {"-d" ,  0, 0, 0 },
        {"-max", 0, 0, 0 },
        {"-min", 0, 0, 0 },
        {"-var", 0, 0, 0 },
    };
    Function to work with the struct
    Code:
    uint32_t ParseDictionary(DICTIONARY *dict[], char** args, uint32_t argc)
    {
        uint32_t dict_len = (sizeof (dict)/sizeof (dict[0]));
        
        uint32_t i, j;
        float val;
        
        for (i = 0; i < argc; i++)
        {
            for (j = 0; j < dict_len; j++)
            {
                if (strcmp(args[i], dict[j]->name)==0)
                {
                    if (IsFloat(args[i+1]))
                    {
                        val = atof(args[i+1]);
                        dict[j]->value = val;
                        dict[j]->found = 1;
                    }
                    else
                        return MSG_INV_ARG;
                }
            }
        }
        
        return MSG_OK; 
    }
    Now I want to pass it to a function
    Code:
    ParseDictionary(&pid_dict, &args[1], argc);
    I get - Error[Pe167]: argument of type "DICTIONARY (*)[6]" is incompatible with parameter of type "DICTIONARY **"
    And this way
    Code:
    ParseDictionary(&pid_dict[0], &args[1], argc);
    I get -Error[Pe167]: argument of type "DICTIONARY *" is incompatible with parameter of type "DICTIONARY **"

    What is wrong?
    Last edited by john7; 02-09-2020 at 04:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing pointer to array of struct pointers
    By _jagged in forum C Programming
    Replies: 2
    Last Post: 08-20-2019, 08:39 PM
  2. passing struct pointer to function.
    By Durango2011 in forum C Programming
    Replies: 3
    Last Post: 10-28-2011, 07:10 PM
  3. Replies: 1
    Last Post: 05-12-2011, 01:02 AM
  4. Passing Pointer-to-struct to a function!!
    By Lau in forum C Programming
    Replies: 5
    Last Post: 11-18-2002, 12:59 PM
  5. Passing a pointer to a struct
    By Natase in forum C Programming
    Replies: 2
    Last Post: 10-02-2001, 10:29 AM

Tags for this Thread