PDA

View Full Version : [Easy Question] Programming in C


number0
Sep30-10, 02:10 PM
Hello,

I just started taking a computer science course involving the program language c. I was wondering if anyone know the command that enables the user to type in a numerical input into the program.

For example:

1. The user runs the program "Math Wizard."

2. The program displays the sentence in printf "What is 2 + 2 equal to?"

3. Then the user gets to type in the value (hopefully 4). <--- I am stuck here because I do not know the command in c that will enable the user to type in a numerical value (or characters) of some sort into the program.

Another example would be in c++. The command "cin" will get the user input. I am looking for a command that is exactly like "cin" but for c not c++.

Can anyone please help me? Thank you in advance.

airborne18
Sep30-10, 02:33 PM
You should post this in the homework area. And if you know how to do it in c++, then read the c++ documentation and it will tell you how it is done in C. Or go through the C standard libs.

jtbell
Sep30-10, 04:20 PM
Try a Google search on "keyboard input in c".

rcgldr
Oct1-10, 12:09 PM
You probably want to use scanf() or some variation of it.

Note that the console function to input a line of data, _cgets(), is broken in Visual Studio since version 2005. _cgetws() is supposed to work if you want to use that.