Suggest the formal arguments

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 15
Reputation: gamodg is an unknown quantity at this point 
Solved Threads: 0
gamodg gamodg is offline Offline
Newbie Poster

Suggest the formal arguments

 
0
  #1
Mar 22nd, 2009
I have a structure
  1. struct Info {
  2. char *name;
  3. char **value;
  4. };
and a function
  1. void addValue(struct Info *info,char *value ,int posVal)
  2. {
  3. int size=strlen(value)+1;
  4. info->value[posVal]= (char *)malloc(size);
  5. strcpy(info->value[posVal],value);
  6. info->value[posVal+1]=NULL;
  7. }
  8.  
  9. Main
  10.  
  11. struct Info info[10]
  12. .......
  13. .......
  14.  
  15. initValArrSize(&info[0],1);
  16. /*
  17. Make size+1 single dimension arrays of size char *
  18. void initValArrSize(struct XMLInfo *info, int size )
  19. {
  20. info->value=(char **)malloc((size+1)*sizeof(char *));
  21. }
  22. */
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
Last edited by Ancient Dragon; Mar 23rd, 2009 at 12:33 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 251
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Suggest the formal arguments

 
0
  #2
Mar 22nd, 2009
>Please suggest the addValue definition to accommodate this change
Looking at the way you call the function. The function definition should look like:

  1. 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.

-ssharish
Last edited by ssharish2005; Mar 22nd, 2009 at 4:44 pm.
"Any fool can know, point is to understand"
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 15
Reputation: gamodg is an unknown quantity at this point 
Solved Threads: 0
gamodg gamodg is offline Offline
Newbie Poster

Re: Suggest the formal arguments

 
0
  #3
Mar 23rd, 2009
Thanks for the reply !!!
I am not returning anything from function addValue. I want to pass
  1. info[0].value[0]
by address. Please suggest the function signature.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 325 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC