Link to home
Start Free TrialLog in
Avatar of simi
simi

asked on

function arguments

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
Avatar of ozo
ozo
Flag of United States of America image

/* 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);
}

Avatar of simi
simi

ASKER

Thanks
Avatar of simi

ASKER

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 ?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial