I'm new to C-programming.
Here's what I'd like to do:
The user inputs T47.2 Scanf recognizes T as a char and 47.2 as a floating point number.
This code doesn't work:
I put the printf and scanf functions in an infinite loop so I can test various inputs.Code:#include <stdio.h> int main() { char letter; float number; while(1) { printf("Letter and Number: "); scanf("%c%f", &letter, &number); } return 0; }
It compiled successfully using c99, and here's what I get after three inputs:
>./a.out
Letter and Number: T47.2
Letter and Number: J73.8
Letter and Number: Letter and Number: I99.1
Something isn't working as I intend for it. It's as if "J" and "73.8" are treated as two separate inputs.
I'd greatly appreciate any input as to how I might fix my scanf format to function properly.