Hi there. This program is to count the number of digits in each string. I'm really not sure if I am using pointers correctly, and not sure if i can compare them to ints like that in the if condition. Currently it wont run and gives errors:C2220: warning treated as error - no 'object' file generated, warning C4702: unreachable code
Any tips appreciated!
Code:
#include <stdio.h>
int count_digits(char* text);
int main(void)
{
char* test[] =
{
"H3ll0", // 2 digits
"Qu3sti0n 3...", // 3 digits
"0ld Pr4ctic4l T3st", // 4 digits
"is", // 0 digits
"e4sy!" // 1 digit
};
for (int k = 0; k < 5; ++k)
{
printf("%s : ", test[k]);
printf("%d digits\n", count_digits(test[k]));
}
return 0;
}
int count_digits(char* text)
{
int count = 0;
for (int i = 0; i < 20; i++)
{
if (text[i] > 47 && text[i] < 58)
{
count++;
}
}
return count;
// TODO: Insert your code here...
// TODO: Temporary stub return...
return 0;
}