You are here:

Advertisement

Supposing we have the following function (c language) that puts a REAL number in a table called input[]:

int getop(char input[])

{

int i,c

while((input[0]=c=getch())==' '|c=='\t';

input[1]='0';

if(!isdigit(c)&&c!='.')

return c;

i=0;

if(isdigit(c))

while(isdigit(input[++i]=c=getch()));

if c=='.'

while(isdigit(input[++i]=c=getch()));

input[i]='\0';

if(c!=EOF)

ungetch(c);

return NUMBER;

}

-how can i transform the above function so that it can only read integers?

-how can i transform the same function so that it can only read numbers in the hex-form (i mean that the base should be 16,for example B65F is the 46687 in the hex system

-could you help me in order to make some kind of a ishex() function that will check if the number given is given in a hex form?(just like the isdigit function, that checks out if the number given is a digit!

any help would be really helpful for me.thanks in advance!

Normally real numbers could apear like 3.567e-10 which lets you have very small and very large numbers. However in your case, it is a simplified version and so it can be easily used for integer. You only need to use the first part which reads the integer part of the real number. Delete the part that manipulates the fraction part (afte '.').

Working with hex numbers is very similar tio integer numbers. You only need to be able to detact the alphabetic digits (see below).

The is a function already implemented for this purpose. It is called isxdigit() and is in ctype.h. See the following microsoft link for more details:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt

- Add to this Answer
- Ask a Question

Rating(1-10) | Knowledgeability = 10 | Clarity of Response = 7 | Politeness = 7 |

Comment | what he said worked but yet it explained it briefly...maybe it's because i dont much c++ i guess i was expecting more of a detailed answer. |

- wcwidth - Linux Command - Unix Command
- Multiplying Numbers in Excel - Product Function - Multiply in Excel
- Count in Excel - Count Numbers in Excel - Excel Auto COUNT Function
- Multiplying Numbers in Excel - Product Function - Multiply in Excel
- Count in Excel - Count Numbers in Excel - Excel Auto COUNT Function

You may ask me about simple to complicated C/C++ programming methods/style and most like questions about network programming in C++.

I'm a professional programer in C++ and network/internet programming.