As you can see from the code, to extract a string from a function I used two methods, the first one is to use a pointer and the second one to use a global array. Both have the same result, but I wanted to know if it is a mistake to use one or the other, since they advised me not to use the globals without giving me an explanation.
forgive my ignorance, unfortunately I have no one to ask and in the search engines I have not found someone who would deal with this topic.
#include <stdio.h>
#include <string.h>
char MyArr[18] = {'\0'}; // Global Array //
// This function use a *Pointer //
const char * MyWordWP( void )
{
return "Hello with pointer";
}
// This function use a global array //
void MyWordArr( void )
{
strcpy(MyArr, "Hello With Array");
}
int main( void )
{
// Read pointer //
const char *MyW = MyWordWP( );
printf( "With Pointer = %s \n" , MyW );
//Set the global //
MyWordArr();
printf( "With Array = %s \n", MyArr);
return 0;
}
Thank you for your support.