1. ## dumb question?

i'm trying to return the number of characters inputted into a scanf statement and don't know how to do it.

so if a user inputs "100", i want the program to store the number 3 for later use.

help??

thanks!

2. You could read the input as a string and then count the characters. Or if you already have a number, try a loop.
Code:
`for(digits = 0; number; number /= 10, digits ++);  /* Untested */`

3. Not getting it. here's a piece of the code.

Code:
```#include <stdio.h>

//int numDigits(int);

int main()
{

int start = time(0);

printf("Enter the maximum number for the game.\n");
scanf("%d", &guessmax);
secnum=rand()%guessmax;

{
{
printf("Your guess is too low, try again.\n");
{
printf("Your guess is too high, try again.\n");
}//else if
} // end while
printf("Great job! The secret number was %d.\n", secnum);
int end = time(0);
int timespent = end - start;
printf("your code took %d seconds.\n", timespent);
system ("PAUSE");
return 0;
}```
After the user inputs guessmax, i want to take that input, turn it into the number of digits, then take that number, and use it to calculate the users score.

the equation that should be used with the score is:

[seconds]/2*[number of digits]

thanks

Think of the way a number is written. For example,

123 = 1*10^2 + 2*10^1 + 3*10^0.

So notice that the power of the last element (namely, 2) is one less then the number of digits. So to get what you're looking for, you could always find that number and add 1. But how do you find that number ?

Here's a hint. The value you're looking for is the number of times you can divide by 10 before your result becomes smaller than 10.

Hope that helps you out.

5. log10(guessmax) +1??

I think its a step in the right direction. i tried integrating it into a function and then calling the function after the correct answer is given and i've been getting a very long negative number. Reference previous code and add this function after the
printf("greatjob...

Code:
```int numDigits(int number)
{
int guessmax;
return log10(guessmax) + 1;
}```
returning it seems like the correct thing to do if I want to use it later? I set up a printf to return the value the function returned and its not working correctly.

6. Something else to consider:
Code:
```#include <stdio.h>

int main()
{
char input[20];
int value, count;
fputs ( "enter an integer: ", stdout );
fflush ( stdout );
if ( fgets  ( input, sizeof input, stdin ) != NULL &&
sscanf ( input, "%d%n", &value, &count ) == 1 )
{
printf ( "value = %d, count = %d\n", value, count );
}
return 0;
}

/* my output
enter an integer: 100
value = 100, count = 3
*/```

7. Code:
```int numDigits(int number)
{
if (number == 0)
{
return(1);
}

if (number < 0)
{
return( 1 + (int) log10( -1.0 * (double) number ) );
}
else
{
return( 1 + (int) log10( (double) number ) );
}
}```