[Easy Question] Programming in C

  • Thread starter number0
  • Start date
104
0
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.
 
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

Mentor
15,327
2,961
Try a Google search on "keyboard input in c".
 

rcgldr

Homework Helper
8,580
473
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.
 

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top