created function for getting length of integer

This commit is contained in:
Václav Šmejkal 2022-04-23 18:07:45 +02:00
parent c3f70c1372
commit 60adbc6f86
2 changed files with 23 additions and 0 deletions

View File

@ -2,5 +2,6 @@
#define WHY2_MISC_H #define WHY2_MISC_H
void checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED void checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED
int countIntLength(int number); //RETURNS LENGTH OF number
#endif #endif

View File

@ -63,3 +63,25 @@ checkVersion()
sleep(5); 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;
}