How Do You Input Numbers in C Programming?

  • Thread starter Thread starter number0
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around how to enable user input for numerical values in the C programming language. Participants explore various commands and approaches for handling input, comparing it to similar functionality in C++.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant seeks guidance on the command in C that allows user input of numerical values, comparing it to the C++ command "cin".
  • Another participant suggests posting in the homework area and recommends consulting C documentation for input methods.
  • A suggestion is made to perform a Google search for "keyboard input in C" as a potential resource.
  • One participant proposes using the function scanf() or its variations for input, while noting issues with the console function _cgets() in Visual Studio.

Areas of Agreement / Disagreement

There is no consensus on a single solution, as participants offer different suggestions and resources without agreeing on the best approach.

Contextual Notes

Some responses imply a reliance on external documentation and resources, and there are mentions of specific issues with certain functions in Visual Studio, which may affect the applicability of the suggestions.

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.
 

Similar threads

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