
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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. |
Advertisements