Let’s say I have a struct called test:
struct test
{
char name[16];
} test;
I want to read the user’s input and put it in the name field. Let’s say the user has typed in "hello" as the input. My code is like this:
struct test test1;
strcpy(test1.name, user_input);
Now the name has 5 characters in it ("hello"), but I want it to have its 16 characters: 5 for the actual input, and the rest white spaces. How can I achieve that?
sprintf() can do it:
output:
or
output