There are two errors in the function.
The first one is that arrays in expressions are implicitly converted to pointers to element types of the arrays.
So if the function has the return expression
return mot_generer;
where mot_generer
is an array then the function return type should be char *
.
The second error is that the function (correctly declared) returns pointer to a local array with the automatic storage duration that will not be aluve after exiting the function.
So either declare the array within the function as having the static storage duration like
char * initialisation_mot_a_trouver(){
static char mot_generer[]="controle";
return mot_generer;
}
Or allocate the array dynamically like
char * initialisation_mot_a_trouver()
{
const char *literal = "controle";
char *s = malloc( strlen( literal ) + 1 );
if ( s != NULL ) strcpy( s, literal );
return s;
}
A third approach is to pass to the function an already created array in main.
In this case the function can look like
char * initialisation_mot_a_trouver( char s[], size_t n )
{
strncpy( s, "controle", n );
s[n -1] = '\0';
// or for example
// fgets( s, n, stdin );
// s[ strcspn( s, "\n" ) ] = '\0';
return s;
}