I am wondering if it is possible to use scanf() to read one line (actually just 1 digit from 0 to 9) and input the data as both a char variable and an integer variable so the user only has to enter the number once. Any help would be greatly appreciated. I am writing in C, using nano as my text editor, gcc as my compiler, and Ubuntu 12.04 as my OS. I also have access to Windoze, if necessary. Thanks in advance!
Share
You can read the integer in with
scanfand then convert it to a character by adding'0'. Since digits are always represented sequentially, this will convert any single digit integer to its corresponding character value.