<< split from long dead thread what would I use to count number of words >>
help with my codes guys..im really new >.<Code:#include<stdio.h> #include<conio.h> #include<string.h> main() { clrscr(); char *str,a[]=".!?"; int index,cnt,sntcnt=0,slen=0; printf("Enter string: "); gets(str); slen=strlen(str); for (index=0;index<slen;index++) { for (cnt=0;cnt<4;cnt++) { if (str[index]==a[cnt]||str[index]=='\0') { sntcnt; } } } printf("Number of sentence in the string: %d",sntcnt); getch(); return 0; } #include<stdio.h> #include<conio.h> #include<string.h> main() { clrscr(); char *str; int index,slen=0,wrdcnt=0; printf("Enter string: "); gets(str); slen=strlen(str); for (index=0;index<=slen;index++) { if (str[index]==' '||str[index]==','||str[index]=='.'||str[index]=='!'||str[index]=='?'||str[index]=='\0') { wrdcnt++; if (str[index]==' ') { wrdcnt--; } else { wrdcnt++; } } } printf("The number of words in the string is: %d",wrdcnt); getch(); return 0; }
if i input more than 2 spaces between the words the program also counts em >.<
same with the sentence count program



LinkBack URL
About LinkBacks


