I'm trying to find the total number of digit for a user's input integer. I'm using the sizeof() function but keeps getting the size is 4 for some odd reason.
For example sizeof(32333) is 5 but it gives me 4. The following is my code, and my sizeof() function is near the middle. Thank you in advance
Expand|Select|Wrap|Line Numbers
- #include<stdio.h>
- int main(void)
- {
- int b;
- int n;
- int output[40];
- int index = 0;
- int condition;
- int size=0;
- printf("Enter base(b) between [1,10], and a number(n), such that digits of n is between[0,b-1] in this format 'n b': ");
- scanf("%d %d", &n, &b);
- printf("n is: %d\n", n); //Test
- printf("b is: %d\n", b); //TEST
- if ((b < 1) || (b > 10))
- {
- printf("Your base is not between 1 and 10");
- return 0;
- }
- if (n < 0)
- {
- printf("n must be positive");
- return 0;
- }
- size = sizeof(n);
- printf("size of n is: %d\n", size);
- /* while (condition != 0)
- {
- output[index] = n % 10;
- printf("number to convert: %d\n", output[index]);
- index++;
- }*/
- return 0;
- }