I have a structure

struct Info {
	char *name;
	char **value;

and a function

void addValue(struct Info *info,char *value ,int posVal)
		int size=strlen(value)+1;
		info->value[posVal]= (char *)malloc(size);


struct Info info[10]

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
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 . addValue(info[0].value[0],"Inspiron");

Please suggest the addValue definition to accommodate this change

>Please suggest the addValue definition to accommodate this change
Looking at the way you call the function. The function definition should look like:

void addValue(struct Info **info, char *value, int posVal);

So that's the function addValue which takes pointer-to-pointer of struct Info type, char pointer and an integer.

This would eliminate the requirement of returning the struct Info * from your addValue. If that makes sense!

NB: Please use the code tags. It makes it more readable and perhaps you can get more help.


Thanks for the reply !!!
I am not returning anything from function addValue. I want to pass


by address. Please suggest the function signature.

This article has been dead for over six months. Start a new discussion instead.