| | |
Suggest the formal arguments
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 15
Reputation:
Solved Threads: 0
I have a structure
and a function
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
c Syntax (Toggle Plain Text)
struct Info { char *name; char **value; };
c Syntax (Toggle Plain Text)
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 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 *)); } */
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
>Please suggest the addValue definition to accommodate this change
Looking at the way you call the function. The function definition should look like:
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
Looking at the way you call the function. The function definition should look like:
C Syntax (Toggle Plain Text)
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"
•
•
Join Date: Mar 2007
Posts: 15
Reputation:
Solved Threads: 0
Thanks for the reply !!!
I am not returning anything from function addValue. I want to pass by address. Please suggest the function signature.
I am not returning anything from function addValue. I want to pass
C Syntax (Toggle Plain Text)
info[0].value[0]
![]() |
Similar Threads
- knoppix or else (Getting Started and Choosing a Distro)
Other Threads in the C Forum
- Previous Thread: Relatively Prime
- Next Thread: stadium coordinator
Views: 325 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o inches infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape socketprograming spoonfeeding stack standard strchr string strings structures student suggestions system systemcall test testautomation unix user voidmain() wab win32 win32api windows.h





