Count The Words In A String | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Getting back to learning after a long break!!
I'm a slow learner but learning with each video

sketchupguru
Автор

what if we like put a condition that we will treat those as words only starting with alphabets?

ihfazhakimsulvi
Автор

Damn, stuff's well explained, thanks :)

adiwa
Автор

Do you have a video covering how to save a full sentence input and then separate each word into an array?

BlackCat-fxkb
Автор

What if I am trying to count the words from a string already obtained from the user via get_string?
I am getting confused with what the "char s[] = ?" would equal in this scenario.
Video was super helpful at explaining the why behind all your lines, thank you!

jor
Автор

I’m having a strange problem where my word count function is counting trailing white spaces as a word

For example using strtok I pass a string that would say “hello my name is \nNice to meet you” (assume the \n is an actually enter key on a .txt file and the trailing spaces r at the end of the line) my word count would return 5 when there’s only 4 words. Any help?

gnesha
Автор

How if there is a nonwords at the beginning of the string?

animeproz
Автор

does this work with non predefined words? like if i make the user input a text?

Mr_wisk
Автор

char strings[] = " one two three four five six seven eight nine\t ten";
int c = 0;
if (strings[0]!=' '){
c++;
}
for (int i = 0; i < strlen(strings); ++i)

{
if (strings[i] == ' ' && isalpha(strings[i+1]) || strings[i] == '\n' && isalpha(strings[i+1]) || strings[i] == '\t' && isalpha(strings[i+1]) ){
c++;
}


/* code */

}
printf("%d", c);
hows this ?

memequeen
Автор

#include<stdio.h>
int main(){
int i=0, word=0;
char text[100]=" ok sfs rfd yes its working.Apple ?? " ;
while(text[i]!='\0'){
switch(text[i]){
case ' ':
if(i==0){ i++;}
else
word++;
while(text[i]<='A'){ i++;}
break;
case '?':
i++;
while (text[i]=='?'){i++;}
break;
case '.' :
if(text[i+1]>='A'){ word++;}
i++;
break;


}

i++; }
printf("%d", word);
}

mehedihasan_
welcome to shbcf.ru