need help wit sum basics

0 Bishwa Nath · March 28, 2015
ok i m new to this....n i am in kinda prblm....
can any1 tel me how to do dis:

ask the user to enter any datatype (may be int or char or float) and then the program displays the type of data entered..

eg. if entered wl display integer.....if enterd 'e' wl display charctr...n if 4,65 is entered it wl display float.

Post a Reply


Oldest  Newest  Rating
0 Dol Lod · April 1, 2015
Here is one way to do it.

1)Use the sizeof method to figure out the largest size of the cast you intend to use and add one to it..
2) Then allocate a character array of that size since each character is one byte. 
3) Read the data into the character array.


Create a union of the largest data type you intend to use and take care of it that way because unions reinterpret bytes and can use them as different data types. 
0 Dol Lod · March 28, 2015
This is just a suggestion, but you could try reading this into a string. Then use variants of printf to print out whatever data is there in various formats.
0 James Juan · April 1, 2015

  1. use a loop to check each character of your input.

  2. use if/iflelse or switch statement if your pattern matched any of your desired output.

0 Bishwa Nath · April 1, 2015
no..the problem is do i create a general veriable to store any datatype entered by the user.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator