Instead of creating the "name" variable as done, do it as follows:
chat name[X];
X is a living number to choose (it can also be a variable set before)
You should also exchange the scanf(...) for this:
fgets(name);
Finally, instead of the printf, use this:
fputs(name);
Therefore, I believe that the following code should work:
int main(){
char nome[50];
printf("Enter your name: ");
fflush(stdin);
fgets(name);
printf("His name is: ");
fputs(name);
}
*I tried to include the library, but the text got weird, anyway, it just uses stdio. h, and maybe stdlib. h (but I believe the latter not).
Explaining your problem: when you declare a char as "char c;", you are reserving ONLY the memory space of a character, when you declare as shown earlier, you declare "X" memory spaces for characters, so we call strings.
Working with strings is often different from working with normal characters, so it is recommended to use other functions such as fputs and fgets.
One more detail, logo ates scanf(...) or fgets(...), it is good to use a "fflush (stdin);", that in Windows, for Linux, the command is different.
%c
is letter,%s
is text– Isac