Please suggest function definition

This is a discussion on Please suggest function definition within the C Programming forums, part of the General Programming Boards category; I have a structure Code: struct Info { char *name; char **value; } and a function Code: void addValue(struct Info ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Question Please suggest function definition

    I have a structure


    Code:
     struct Info { 
        char *name; 
        char **value; 
    }
    and a function


    Code:
     void addValue(struct Info *info,char *value ,int posVal) 
    { 
            int size=strlen(value)+1; 
            info->value[posVal]= (char *)malloc(size); 
                       strcpy(info->value[posVal],value); 
                    info->value[posVal+1]=NULL; 
    }
    Main


    Code:
     struct Info info[10] 
    ....... 
    ....... 
    
    initValArrSize(&info[0],1); 
    /* 
    Make size+1 single dimension arrays of size char * 
    void initValArrSize(struct XMLInfo *info, int size ) 
    { 
        info->value=(char **)malloc((size+1)*sizeof(char *)); 
    } 
    */
    now calling addvalue


    Code:
     addValue(&info[0],"Inspiron", 0);
    I want to change it to info[0].value[0] so that it reduces the number of arguments in addValue method and also pass it by reference so that changes are reflected in main
    ex .
    Code:
     addValue(info[0].value[0],"Inspiron");
    Please suggest the addValue definition to accommodate this change

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    Quote Originally Posted by gamodg View Post
    ... I want to change it to info[0].value[0] so that it reduces the number of arguments in addValue method and also pass it by reference so that changes are reflected in main
    ex .
    Code:
     addValue(info[0].value[0],"Inspiron");
    Please suggest the addValue definition to accommodate this change
    Perhaps something like:
    Code:
    addValue(&info[0].value[0], "inspiron");        /* call the function */
    
    addValue(char **infoval, const char *p) { ... } /* function definition */
    Last edited by itCbitC; 03-22-2009 at 07:48 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM

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