count digit until you get number of digits you want
<p>I'm new to coding. I'm now learning C programing. I'm having a problem with counting digits. My objective is to only accept a fixed number of digits in the input. For example I want user to input only 7 digits number, so when they input anything else than a 7 digits number, the program should ask them to input again until it gets 7 digits number. Here is my attempt:</p>

<pre><code>int n, count = 0;
printf("Please enter number:");
scanf("%d", &amp;n);
printf("\n");

while (n != 0)
{
    n /= 10;
    count++;
}

printf("%d", count);
if (count != 7)
{
    printf("You can use only 7 digits numbers");
}
</code></pre>