如何查找给定输入的数据类型 [英] How to find datatype of given Input

查看:90
本文介绍了如何查找给定输入的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我的朋友参加了一次采访,因为他没有提出问题。问题就像这个程序找到给定输入的数据类型他问我,我能够破解这个





Today my friend attend an interview , in that he was failed to ans a question. The question was like this Program to find the datatype of a given Input He asked me and I was able to crack up to this


include<stdio.h> 
main() 
{ 
  char n; 
  printf("\nEnter a character: "); 
  scanf("%c",&n); 
  if(isdigit(n)) 
     printf("\nInteger"); 
  else 
     printf("\nCharacter"); 
}







但是它只会告诉整数或者是charector,输入怎么样像浮动双。任何人都可以帮助我。在这里我们可以使用任何编程语言。




But it will tell only integer or charector, how about for an inputs like float double. Can any one help me inthis. Here we can use any programming language.

推荐答案

一般来说,一个字符不能代表整数。它只能代表一个数字(你知道一个整数是一个或更多个数字的序列,可能以符号为前缀)。

更是如此,单个字符不能表示一个浮点数或一个双精度数。

为了告诉字符串 所代表的值的类型,你需要写一个词法分析器(请参阅维基百科的词法分析 [ ^ ])。
Generally speaking, a character cannot represent an integer number. It can just represent a digit (you know an integer is a sequence of one or more digits, possibly prefixed by the sign).
Even more so, a single character cannot represent a float or a double.
In order to tell the type of a value represented by a string, your need to write a lexer (see "Lexical analysis" at Wikipedia[^]).


这篇关于如何查找给定输入的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆