It is good that you also posted your code within your post to make it more accessible than as an attachment, but you should post it within [code][/code] bbcode tags:
Code:
#include <stdio.h>
void main() {
printf("Welcome to nameage\n");
char name[10];
int age;
printf("Input name: ");
scanf_s("%c", &name); // Why does it skip the age?
printf("Input age: ");
scanf_s("%d", &age);
printf("Name: %s", name); //Why does it print weird characters?
system("pause");
return 0;
}
The main problem is that %c is the format specification to read a character with the scanf family of functions, whereas you wish to read a string. Therefore, you should have written:
Code:
scanf("%9s", name);
Notice that I used "%9s" instead of just "%s" because the field width should be specified so as to prevent buffer overflow. Furthermore, because in this context an array would be converted to a pointer to its first element, I passed name rather than &name as an argument. If you absolutely insist on using scanf_s rather than scanf, then you must make use of the "security enhancement" for reading strings and hence pass the buffer size too:
Code:
scanf_s("%9s", name, (unsigned)_countof(name));
(Example derived from the online MSDN entry for scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l, so if it doesn't work, not my problem as I would have just used scanf.)
By the way, the main function returns int, not void, and even where your compiler might permit it to have a void return type, you are explicitly returning 0 so it should be int return type anyway.
Also, you should consider checking the return value of scanf (or scanf_s) to see if the input was successfully read.