![]() |
[c debian linux] Please suggest the function definition
I have a structure
PHP Code:
and a function PHP Code:
Main PHP Code:
PHP Code:
now calling addvalue PHP Code:
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 Code:
Please suggest the addValue definition to accommodate this change |
Re: [c debian linux] Please suggest the function definition
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)Why? |
Re: [c debian linux] Please suggest the function definition
Thanks for the reply.
I made the following changes. PHP Code:
Please help !!! |
Re: [c debian linux] Please suggest the function definition
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? |
Re: [c debian linux] Please suggest the function definition
Hi
Thanks for the reply !!!! Quote:
|
Re: [c debian linux] Please suggest the function definition
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? |
| All times are GMT +5.5. The time now is 22:12. |