Question: I am learning C and I want to implement a function that returns to main function a string. I have read some topics here but I got confused.. I wrote:

```
#include <stdio.h>
#include <string.h>

char myPrint(int); 

int main()
{ 
   char msg[10];

   msg = myPrint(1);

   printf("\n %s \n", msg); 
} 

char myPrint(int n)
{ 
   char msg[10];

   if(n==1)
      strcpy(msg, "ACCEPT");
   else
      strcpy(msg, "DENY");

   return msg;
}

```

and I get a bunch of warnings and error.. I read [this](http://www.tutorialspoint.com/c_standard_library/c_function_strcpy.htm) for the usage of the strcpy 
and many others links relevant to this topic but I didn’t get it..

Answer: 
Declare your function as 

```
char *myPrint(int n);

```

Do not return the local variable `msg` from your function - it ceases to exist after `myPrint` function.

```
 if(n==1)
     return "ACCEPT";
 else
     return  "DENY";

```
Declare your function as 

```
char *myPrint(char *ptr, int n);  

```

to return string from your function.  

Call it from your `main` function as 

```
printf("\n %s \n", myPrint(msg, 1));  

```

Your function 

```
char *myPrint(char *msg, int n)
{ 
    if(n==1)
         strcpy(msg, "ACCEPT");
    else
         strcpy(msg, "DENY");

    return msg;
}    

```

But in this case there is no need to return string from your function as it will update your `msg` array in `main`.