How Do You Input Numbers in C Programming?

  • Thread starter Thread starter number0
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
To enable user input in a C program, the command to use is "scanf()". This function allows the program to read numerical values or characters entered by the user. For example, in a program like "Math Wizard," after displaying a prompt with "printf," you can use "scanf()" to capture the user's input. It's important to note that while "cin" is used in C++, "scanf()" serves a similar purpose in C. Additionally, users should be aware that the console function "_cgets()" is broken in Visual Studio since version 2005, but "_cgetws()" can be used as an alternative for inputting data. For further guidance, consulting C standard libraries or conducting a Google search on "keyboard input in C" can provide additional resources.
number0
Messages
102
Reaction score
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.
 
Technology news on Phys.org
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.
 
Try a Google search on "keyboard input in c".
 
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
Replies
14
Views
3K
Replies
12
Views
3K
  • · Replies 14 ·
Replies
14
Views
34K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
65
Views
5K