created function for getting length of integer
This commit is contained in:
parent
c3f70c1372
commit
60adbc6f86
@ -2,5 +2,6 @@
|
||||
#define WHY2_MISC_H
|
||||
|
||||
void checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED
|
||||
int countIntLength(int number); //RETURNS LENGTH OF number
|
||||
|
||||
#endif
|
||||
|
22
src/misc.c
22
src/misc.c
@ -63,3 +63,25 @@ checkVersion()
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
int countIntLength(int number)
|
||||
{
|
||||
int returning = 1;
|
||||
int buffer = 10;
|
||||
|
||||
//CHECK FOR NEGATIVE NUMBER
|
||||
if (number < 0)
|
||||
{
|
||||
returning++;
|
||||
number *= -1;
|
||||
}
|
||||
|
||||
//COUNT LENGTH
|
||||
while (buffer <= number)
|
||||
{
|
||||
buffer *= 10;
|
||||
returning++;
|
||||
}
|
||||
|
||||
return returning;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user