473,378 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

finding the type of an argument in c?

hi,
this is a very strange question from me. i want to find the type of an argument . suppose if user is giving input from commandline, i want to know the type of the value that he has given.
EX: suppose user has given 10,10.34 as two arguments, how could i find the type of the value i.e 10 -- integer, 10.34-- float.. like that
let me know if there are any built-in functions or provide me the solution..
Nov 19 '12 #1
6 1937
weaknessforcats
9,208 Expert Mod 8TB
Command line arguments appear in your program as strings. So and argument of 123 will appear as a string of 3 chars + a null terminator.

If you need an int with a value of 123 you will have to convert the string to an integer.

Therefore, you always know the types because they come in as char and if you convert them to another type, then you need to remember that type.
Nov 19 '12 #2
whodgson
542 512MB
The program could establish the type of the variable using sizeof().
Nov 20 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
sizeof does not report the type. It only tells you how much stack memory is used by that object.
Nov 20 '12 #4
whodgson
542 512MB
to: weaknessforcats
yes but couldn't you then compare what you got with sizeof(int),
sizeof(char),sizeof(double),sizeof(float)...etc and then conclude what the type was on that machine? Realize there may/would still be some ambiguities.
Anyway... you have pointed out (and I was unaware of)that we are only dealing with strings of characters so the answer is char or 1 byte.
Nov 22 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
A float is 4 bytes and an int is 4 bytes. But the format of the bits is different. Knowing the 4 doesn't tell you the type.

If you have ambiguities like this, then you cannot use this method to tell you the type since you are in the land of indeterminate results.
Nov 22 '12 #6
whodgson
542 512MB
@@@@@@@@@@@@@@@@@@@@@Yes...thank you.
Nov 24 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Spiegel | last post by:
Hi all, I'm trying to create a subclass of an ArrayList that is intended specifically for holding FileInfo objects. My idea to restrict this is to override the Add and AddRange methods to allow...
2
by: CoolPint | last post by:
As a self-exercise, I am trying to write a generic Priority Queue, which would store any type and and accept any user-definable "priority" function. After much tinkering, I came up with...
2
by: gao_bolin | last post by:
I have the following situation: class A { public: virtual ~A() {} }; template < typename T > class B : public A
2
by: newbie29 | last post by:
I get this error "invalid type argument of '->'". It occurs when: if (num_process->t_pid == -1) { .... } I have defined the struct num_process in the same file as where the above is...
1
by: Brian Henry | last post by:
Just thought maybe someone here would like to know this. It's an example code I just created quickly on how to figure out the name of a type of file based on its extension (say for example .DOC)...
1
by: tsarevich | last post by:
create type my_type (my_test text, my_int integer); create function my_function(my_type) returns timestamp as 'begin return (current_timestamp); end; ' language 'plpgsql';
5
by: Sheldon | last post by:
Hi Everyone, I have defined a function: struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct Transient retv); and in the code: struct Transient arrFromHdfNode(HL_NodeList...
7
by: mirandacascade | last post by:
The questions are toward the bottom of this post. Situation is this: 1) Access 97 2) Multi-user appplication 3) SQL Server 2000 4) Sporadically (i.e. less than 1% of the time) encounter the...
4
Siddarth777
by: Siddarth777 | last post by:
#include<stdio.h> main() { int *a=5; int **p=&a; fflush(stdin); printf("%u,%u,%d",p,*p,**p); } getting compiled perfectly but am getting
2
by: Stephanie Smith | last post by:
I always get this error message! Here's the code: #include <stdio.h> #include <stdlib.h> int main(void) { char *string; char length_string = 0; char buffer_for_string = 0;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.