hi everyone, i made this code but i'm not sure if it's 100% correct
Code:
#include <stdio.h>
#include <string.h>
int count(char x[]){
int sum=0,j,cw=0;
for (j=cw;j<=strlen(x)-1;j++){
while(x[j]!=' '){
cw++;
j++;
}
if (x[j+1]!=' ' && !isdigit(x[j+1])){
sum++;
}
}
if (x[0] == ' ' || isdigit(x[0])){
sum--;
}
return sum;
}
int main(void){
char x[1000] = " a b c d ef g 90123012031203 hi jjj 0210312093091230123";
printf("%d\n",count(x)); //the result is 8
getchar();
return 0;
}
it prints me the correct results for different input, but is there any other better/smarter way to do this?
thanks