Solved

function arguments

Posted on 1998-07-28
4
361 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
logging Access violation 6 19
Microsoft vcsetup.exe and vcssetup.exe 8 421
Understanding the meaning of Portability in Embedded System Programming 8 139
C#, VS15, StructLayout 1 134
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…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

815 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

11 Experts available now in Live!

Get 1:1 Help Now