
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Difference between scanf() and gets() in C
In C language both scanf() and gets() functions are defined to get input from external source and pass to system as input. Now there is some characteristics difference between both the functions.
Following are the important differences between scanf() and gets() in C −
Sr. No. | Key | scanf() function | gets() function |
---|---|---|---|
1 | Definition | The scanf() function can read input from keyboard and stores them according to the given format specifier. It reads the input till encountering a whitespace, newline or EOF. | On other hand gets() function is used to receive input from the keyboard till it encounters a newline or EOF. The whitespace is considered as a part of the input. |
2 | WhiteSpace | In scanf() function white-space is not considered as input character and also it stops reading input from external source if any white-space is encountered in between. | On other hand in get() function white-space is considered as input character and also it does stops reading input from external source if any white-space encountered in between it continue its reading from input source. |
3 | Syntax | scanf() function takes the format string and list of addresses of variables. e.g. scanf(“%d”, &number); | On other hand get() function takes the name of the variable to store the received value. e.g. gets(name); |
4 | DataType | scanf() function can read multiple values of different data types. | However on other hand get() function will only get character string data. |
- Related Articles
- Problem with scanf() when there is fgets()/gets()/scanf() after it in C
- scanf() and fscanf() in C
- Return values of printf() and scanf() in C
- fgets() and gets() in C
- Difference between Structures in C and C++
- Difference between C and C++.
- Difference Between C# and C++
- Divide ₹7000 Among A B and C Such That A Gets 50% Of What B Gets And B Gets 50% Of What C Gets
- Difference between strncmp() and strcmp() in C/C++
- Difference between %p and %x in C/C++
- Difference between float and double in C/C++
- Difference between C# and Visual C#
- Difference between Array and Pointers in C
- Difference between Structure and Union in C
- Difference between == and .Equals method in c#

Advertisements