Hi
I am trying to write a code that accpets a string of characters. I need to count the number of digits in that string and return the counted value.
This is my code
Quote:
include <stdio.h>
#include <ctype.h>
#define MAX 15
int digcnt(int c);
int main( int argc, char *argv[]) {
char x[MAX];
int c;
printf("Enter a string of chars and digits:\n");
// fgets(x, MAX, stdin);
while(( c= getchar()) !='\n') {
c =x[MAX];
}
digcnt(c);
return 0;
}
int digcnt(int c) {
int b;
for(b=0; b<MAX; b++) {
if(isdigit(c)){
b++;
}
}
printf("There are %d digits in the string.\n", b);
return b;
}
Also how do i check if the string (in my case, x[MAX]) contains digits?
My output is that it gives me the number of MAX as the number of digits.
All help is appreciated.