Good evening, friend. As you say there are better ways to do this reading, but as you opted for a specific one I will help.
#include <stdio.h>
#include <stdlib.h>
void main(){
char nome[6];
printf("Qual o seu nome?\n");
scanf("%c%c%c%c%c", &nome[0],&nome[1],&nome[2],&nome[3],&nome[4]);
printf("O seu nome e: %c%c%c%c%c\n",nome[0],nome[1],nome[2],nome[3],nome[4]);
}
Explanation:
When declaring the char arrangement you should have put 'name[6]' instead of 'name[4]'. It should be done so, because when declaring a char arrangement it should be taken into account that the last position will be reserved to the character' n'.
Example:
'name[4]' would be stated as follows: ’D', 'a', 'v', 'i'
'name[6]' would be stated as follows: ’D', 'a', 'v', 'i', ’d', ' n'
Note that in the second example you have the 5 spaces for the letters and a space for the ' n' (important character in a char arrangement). The first example the letter 'i' basically "invades" the place of ' n', this is not something positive.
There have also been some other syntax problems in the code.
It’s them:
Line 3: a return type or a void should be declared for the main function
Line 6: a space was placed after declaring '%c'. Correct mode: "%c%c%c%c".
Line 6: only four '%c' was placed and there should be five.
Satisfactory answer, thank you
– David Faria