I have a structure PHP: struct Info { char *name; char **value; }; and a function PHP: 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 PHP: struct Info info[10] ....... ....... [/LEFT] [LEFT]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 PHP: 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 . PHP: addValue(info[0].value[0],"Inspiron"); Please suggest the addValue definition to accommodate this change
info[0].value[0] is of type char*, and so in "Inspiron", so I'd guess something like: Code: void addValue(char *info_value,char *value) > I want to change it to info[0].value[0] so that it reduces the number of arguments Why?
Thanks for the reply. I made the following changes. PHP: void addValue(char *info,char *value ){ int size=strlen(value)+1; info= (char *)malloc(size); strcpy(info,value);} When i try to run it the program terminates abruptly. Please help !!!
If you want to modify info[0].value[0], then you have to pass the address in and dereference that pointer within the function: Code: void addValue(char **info,char *value ) { int size=strlen(value)+1; *info= (char *)malloc(size); strcpy(*info,value); } void test() { addValue(&(info[0].value[0]),"Inspiron"); } Again: why do you want to do this? Also, what about posVal?
Again: why do you want to do this? i.e. "so that it reduces the number of arguments" so the question is: Why do you want to reduce the number of arguments? What benefit do you think you will get from that? Have you done code profiling and found this to be a bottleneck of some kind?