Solved

function arguments

Posted on 1998-07-28
4
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

622 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