Categories
c input printf string

How do I properly ‘printf’ an integer and a string in C?

I have the following code:

char *s1, *s2;
char str[10];
printf("Type a string: ");
scanf("%s", str);
s1 = &str[0];
s2 = &str[2];
printf("%s\n", s1);
printf("%s\n", s2);

When I run the code, and enter the input “A 1” as follow:

Type a string: A 1

I got the following result:

A
�<�

I’m trying to read the first character as a string and the third character as an integer, and then print those out on the screen. The first character always works, but the screen would just display random stuffs after that…. How should I fix it?