I wrote the following code to convert a number into a "look and say" value. Everything works properly except for one thing. I cannot enter an integer value greater than 2,147,483,647 (the maximum long int). However, I'm expecting an input upto the maximum value of unsigned long int which is 4,294,967,295. When I enter anything greater than 2,147,483,647 I get an overflow error.
Am I mixing some type values?
Code:
#include <stdio.h>
#include <math.h>
int main(void)
{
unsigned long int inValue;
int length, temp1, temp2, count;
printf("Enter a non-negative integer \n");
scanf("%lu", &inValue);
length = (int) log10(inValue);
count = 1;
while(length >= 0){
temp1 = (int) inValue/pow(10,length);
inValue = inValue - (temp1 * pow(10,length));
temp2 = (int) inValue/pow(10,length-1);
if(temp1 == temp2 && length != 0){
count++;
length--;
continue;
}
printf("%d%d", count, temp1);
count = 1;
length--;
}
printf("\n");
return 0;
}
Am I mixing some type values?