My C code is kinda drunk : I'm so confused here... why this code of mine doesn't work as it SHOULD be..

Here's the code: 

    void print(int x) {

	x = 140;
	int i,total, length, XLength;   

		if (x < 10){XLength = 0;}
			else {
					int sum = 1;
					for (i = 0 ; i < 10 ; i++){
					total = 10 * sum; sum = total; length = x / total;
					if (length < 10 && 1 <= length){ XLength = i+1; break;}
					}}
			XLength = pow(10,XLength);
			printf("%d\n",XLength);
			}
Let me explain how the code should works first: It takes an integer x and print out the highest power of 10 value it can be divided by.
So if X = 80, it should print 10 and if x = 12435, it should print 10000.
But... this doesn't work with my code perfectly... if x = 140, it prints 99 but.. if x = 1400, it prints 1000.. then again, if x = 14000 it prints 9999 and if x = 140000 it prints 100000 and the sequence continues... 

I've already tried exactly the same code in Java and it works perfectly!!
Why does it not works in C??
