0

So basically I have a a program in C, whose point is to look organized. I'd like my program's cursor not to move after I confirm my Scanf statement. Heres example part of my program and its output:

#include <stdio.h>
int main()
{
char input[10];
int voltage=220;
printf("What do you want to know\n");      //no need to correct me on this part please
scanf("%s", input);
if (strcmp("voltage",input)==0)
     printf(" = %d\n", voltage);
/* Imagine other string comparisons (resistance, current) here*/
return 0;
}

So this program for input "voltage" would output something like this: voltage //what I just inputed via scanf = 220 // \n because I pressed enter after inputing.

What I wanted is:

voltage = 220

I dont know Is there reverse \n function that I dont know about.

1 Answers1

0

There is no standard way in C to read input without pressing Enter. You will have to go for platform specific functions.

There are lots of questions here in StackOverflow that cover this, such as Capture characters from standard input without waiting for enter to be pressed

Community
  • 1
  • 1
Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70
  • So theres not much I can do? well thank you anyways sir. – user3272749 Feb 04 '14 at 22:03
  • @user3272749 Well, there is, it just might not be as easy as you thought it would. As I said, you have to use platform specific solutions. If you only want this to work on linux, try the curses library. – Filipe Gonçalves Feb 04 '14 at 22:05