Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
Program that allows integer input only
Next article icon

Program to find out the data type of user input

Last Updated : 26 Dec, 2017
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

Take a input from user and find out the data type of input value.

Examples :

  Input : geek  Output : The input is a string    Input : chetna  Output : The input is a string    Input : 4  Output : The input is a integer  

Below is C program to find the datatype of user input :




// C program to find data type
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
# define MAX_INPUT 100
  
int main()
{
    // To read input
    char value[MAX_INPUT] = "";
  
    // To store numeric value of input if a 
    // number (float or integer)
    double temp;
  
    // To store integral value of input
    int n;
  
    // To store string value of input
    char str[MAX_INPUT] = "";
  
    // Precision for integer checking
    double val = 1e-12;
  
    fgets(value, 100, stdin); // Read input
  
    // Check for integers.
    if (sscanf(value, "%lf", &temp) == 1) 
    {
        n = (int)temp; // typecast to int.
        if (fabs(temp - n) / temp > val) 
            printf("The input is a floating point\n");        
        else 
            printf("The input is an integer\n");        
    }
  
    // Check for string 
    else if (sscanf(value, "%s", str) == 1)     
        printf("The input is a string\n");
      
    else // No match.    
        printf("input not recognized\n");    
}
 
 

Output :

4  The input is an integer


Next Article
Program that allows integer input only

C

chetna_chandra
Improve
Article Tags :
  • C Programs
  • C/C++ Puzzles
  • School Programming
  • C-Data Types

Similar Reads

  • C Program to Find the Size of int, float, double and char
    Write a C program to find the size of the data types: int, float, double, and char in bytes and print it on the output screen. Examples Input: charOutput: Size of char: 1 byte Input: intOutput:Size of int: 4 bytes Different Methods to Find the Size of int, float, double and char in CWe can find the
    4 min read
  • How to Take Operator as Input in C?
    In C, an operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. We may need to take operator as an input in some cases. In this article, we will learn how to take an operator as input in C. Get Input Operator in CTo take an operator as input in C, we
    2 min read
  • Program that allows integer input only
    Given an input value N, the task is to allow taking only integer input from the user. Now, if the user enters any input other than an integer, that is, a character or symbol, it will not be accepted by the program. Below is the C program to implement this approach: [GFGTABS] C // C program for the a
    3 min read
  • C Program to Print the Program Name and All its Arguments
    The command-line argument (CLA) is the parameter provided in the system upon request. Command-line conflict is an important concept in system C. It is widely used when one needs to control your system from the outside. Command-line arguments are transferred to the main () path. Argc calculates the n
    2 min read
  • Lex Program to accept a valid integer and float value
    Lex is a computer program that generates lexical analyzers. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The commands for executing the lex program are: lex abc.l (abc is the file name) cc lex.yy.c -efl ./a.ou
    1 min read
  • How to Take Multiple Input in C?
    In C, we use scanf to take input from the user, and often it is necessary to take multiple inputs simultaneously. In this article, we will learn about how to take multiple inputs from the users in C. Multiple Inputs From a User in CTo take multiple inputs from users in C, we can declare an array to
    2 min read
  • C Program For Char to Int Conversion
    Write a C program to convert the given numeric character to integer. Example: Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3. Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9. Different Methods to Convert the char to int in CThere are 3
    3 min read
  • How to Read Input Until EOF in C?
    In C, reading input until the End of the File (EOF) involves reading input until it reaches the end i.e. end of file. In this article, we will learn various methods through which we can read inputs until EOF in C. Reading Input Until EOF Read Input Until EOF Using getchar()Read Input Until EOF Using
    5 min read
  • Program to check if a number belongs to a particular base or not
    TiGiven a number N and its radix base R, find whether its valid or not according to its radix base. Find valid/invalid number for any base ranging from binary to base32. Examples: Input : 1000101010001 Output : Valid 1000101010001 is valid binary number. Input : 0xFFFAG Output : invalid 0xFFFAG is n
    7 min read
  • C Compound Data Types Practice Problems
    Compound Data Types are those data types in C that are created using basic data types. They provide an interface to use the built-in data types is different ways to satisfy our requirement. They are frequently used to handle real world cases it is a must for programmers to have good clear understand
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences