diff --git a/include/misc.h b/include/misc.h index b7c035e..917c67e 100644 --- a/include/misc.h +++ b/include/misc.h @@ -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 diff --git a/src/misc.c b/src/misc.c index 97962ad..7ba00e7 100644 --- a/src/misc.c +++ b/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; +}