Hello, I’m writing a program that reads stdin using scanf() and extracts 2 pieces of information to use later. I want to use string formatting and scanf() to do this since I’m very new to C and want to learn more about scanf().
So far I am able to correctly extract the first part of my input, but printf outputs an incorrect value for the next part. This is the kind of input I am reading every time (I want to capture 10 characters and 1 int):
I want to place abcdefghij and 1 into two separate variables. This is what I have done:
Code:
int main(){
char myString[11];
int myString2;
scanf("%s*%d", &myString[0], &myString2);
printf("%s %d\n", myString, myString2);
return 0;
}
This should output: abcdefghij 1, but instead I get: abcdefghij 0.
There are no errors or warnings when compiling or running either. If someone could point out my mistake I would be really grateful! Thank you!