I started creating a data collection and usage application with the following code:
#include <stdio.h>
#include <string.h>
int main() {
int idade = 0;
char nome[20];
printf("Hello! How old are you? ");
scanf("%d", &idade);
while (idade == 0) {
printf("\nAge cannot be 0 nor be decimal. Re-enter your age: ");
scanf("%d", &idade);
}
printf("And what's your name? (write up to 20 characters, only 1st name) ");
scanf("%[^\n]s", nome);
printf("\nHello %s, aged %d!\n", nome, idade);
return 0;
}
But after compiling with GCC, the output is:
Hello! How old are you? 123 And what's your name? (write up to 20 characters, only 1st name) Hello �����dU��m�, aged 123!
What do I have to change?