Question #25925

In a C program that uses a void function where can i add a scanf function that lets the user input a character for example, scanf("%c", &d); that doesn't require to store memory but needs it before each unspecified amount of lines.
1

Expert's answer

2013-03-13T08:40:28-0400

In windows, you can use the header `<conio.h>` which has a function called `getch()` for getting a char directly from the console.

Example:


#include<stdio.h>
#include<conio.h>
main()
{
printf("Waiting for a character to be pressed from the keyboard to exit.\n");
getch();
return 0;
}


Example for Dev C++ compiler:


#include<stdio.h>
main()
{
printf("Waiting for a character to be pressed from the keyboard to exit.\n");
getchar();
return 0;
}


In Linux you can download `<ncurses.h>` library and then you can use `getch()`.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS