Solved

function arguments

Posted on 1998-07-28
4
359 Views
Last Modified: 2010-04-15
Hi
Is there a way I could reffer the arguments of a function the same way as the arguments for the main function ?
ex.

void dummyFunction(char* arg1, char* arg2, char* arg3)
{
int count;
    for(count = 0; count < 3; count++)
    {
            alocate memory for each argument one by one
    }
}

Thanks
0
Comment
Question by:simi
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1251839
/* I'm not sure what alocate memory for each argument one by one is supposed to do, but perhaps you mean something like this? */
void dummyFunction( char *args[3] ){
  int count;
   for( count = 0; count < 3; count++ ){
       char *copy;
       copy = malloc(strlen(args[count])+1);
       strcpy(copy,args[count]);
       printf("%s\n",copy);
       free(copy);
   }
}
main(){
   char *args[3] ={"hello", "world", ""};
   dummyFunction(args);
}

0
 

Author Comment

by:simi
ID: 1251840
Thanks
0
 

Author Comment

by:simi
ID: 1251841
I want to grade your answer but the system just provide me with the posibility to write a comment. The grading part has vanished.
How can I grade it ?
0
 
LVL 84

Accepted Solution

by:
ozo earned 20 total points
ID: 1251842
You can't grade it because I didn't submit an answer, because I wasn't sure what the question was.
But since it sounds like you have nevertheless gotten what you needed, I'll submit one now.
If there was anything you wanted clarified, please comment.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now