0
votes

So this is my code so far:

printf("Input:\t   Radius:\tSurface Area:\t Circumference:\t    Volume:\n\n");
scanf("%lg", &diameter);
printf("%lg%lg\t\t%-12lg\t\t%-12lg\t\t%-12lg\n\n", diameter, calcRadius(diameter), calcSurfaceArea(diameter), calcCircumference(diameter), calcVolume(diameter));

My output appears like this:

Input:     Radius:      Surface Area:    Circumference:     Volume:

99
9949.5          30775.1                 310.86                  507790

Press any key to continue . . .

How can I make the output appear like this instead:

Input:     Radius:      Surface Area:    Circumference:     Volume:

  99      9949.5          30775.1       310.86             507790

Press any key to continue . . .

In short, I realize that after scanf() is used and the user presses enter, the printf() automatically prints to the new line. How can I get it so it will print on the same line the user typed a number onto, even when the user presses enter.

Should I be using a different function for getting input, or a completely different method altogether?

3

3 Answers

0
votes

You can use the termios library to set STDIN into non-canonical and non-echo mode, and start echoing the characters yourself so that there is no newline printed. Also, you'd have to use your own impmentation of scanf if you want to go this route:

http://www.gnu.org/software/libc/manual/html_node/Noncanon-Example.html

0
votes

You need to look into the curses library to do that sort of thing.

0
votes

You know what scanf would do. For your program, you could just remove printing diameter in your printf()

printf("Input:\t   Radius:\tSurface Area:\t Circumference:\t    Volume:\n\n");
scanf("%lg", &diameter);
printf("\t%lg\t\t%-12lg\t\t%-12lg\t\t%-12lg\n\n", calcRadius(diameter), 
calcSurfaceArea(diameter), calcCircumference(diameter), calcVolume(diameter));