Getting back to learning after a long break!! I'm a slow learner but learning with each video
@PortfolioCourses Жыл бұрын
Awesome to hear you're back to learning! :-)
@Tad45462 жыл бұрын
Damn, stuff's well explained, thanks :)
@PortfolioCourses2 жыл бұрын
You’re welcome! :-)
@ihfazhakimsulvi6494Ай бұрын
what if we like put a condition that we will treat those as words only starting with alphabets?
@justcurious19405 ай бұрын
Interesting method.
@BlackCat-fx9kb2 жыл бұрын
Do you have a video covering how to save a full sentence input and then separate each word into an array?
@PortfolioCourses2 жыл бұрын
Not exactly. But this video might help you with that, you could split the words in the sentence based on 'space': kzbin.info/www/bejne/jKGZgHiCgJmao9E.
@petepudrick2 жыл бұрын
Thank you, it helps a lot !
@PortfolioCourses2 жыл бұрын
You’re welcome! :-)
@animeproz67802 жыл бұрын
How if there is a nonwords at the beginning of the string?
@PortfolioCourses2 жыл бұрын
We could use an extra loop before the for-loop to skip through this nonword content, like this code below. Maybe this version will become a new video for handling this case. :-) #include #include int word_count(char *s); int main() { char s[] = " This is, the way. Another..."; int count = word_count(s); printf("%d ", count); return 0; } int word_count(char *s) { int len = strlen(s); int count = 0; char nonwords[] = " .,; \t"; // skip though a possible nonword at the start of the string int i = 0; while (i < len) { if (strchr(nonwords, s[i]) == NULL) break; i++; } for ( ; i < len; i++) { while (i < len) { if (strchr(nonwords, s[i]) != NULL) break; i++; } count++; while (i < len) { if (strchr(nonwords, s[i]) == NULL) break; i++; } } return count; }
@duytran4102 жыл бұрын
Thank you sir . Your content is gold. I watch all your video and practice. Thanks again ^_^ #include #include #include int main(){ char str[] = " ;.Welcome ,. to c 2022"; int letter = 0; int word = 0; int digit = 0; int length = strlen(str); char not_letters[] = " ,;."; for(int i = 0 ; i < length; i++) { if(isalpha(str[i])){ while(i < length) { if(strchr(not_letters, str[i]) != NULL) break; // increase loop i++; // count letter letter++; } word++; } if(isdigit(str[i])) { digit++; } } printf("Letter: %d ", letter); printf("Word: %d ", word); printf("Digit: %d ", digit); return 0; }
@jor1994 Жыл бұрын
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!
@PortfolioCourses Жыл бұрын
Great question Jordan! :-) The get_string() function appears to be from the CS50 course, so the function isn't really part of the C programming language officially. I would recommend using the standard C way of dealing with strings, which is to store them into a char array. This video may help you with accepting string input from the user in other ways: kzbin.info/www/bejne/nGmYaWyPbrF7fsk.
@jor1994 Жыл бұрын
@@PortfolioCourses Thank you so much for replying, you are correct on the cs50 course. Coming from python and taking this course to get a better understanding of CS in general, your videos have really helped connect some dots.
@PortfolioCourses Жыл бұрын
That's excellent hear that Jordan! :-)
@gnesha5904 Жыл бұрын
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 Nice to meet you” (assume the 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?
@PortfolioCourses Жыл бұрын
I don't know, people would likely need to see your code to be able to help you with that problem. :-)
@Mr_wisk2 жыл бұрын
does this work with non predefined words? like if i make the user input a text?
@PortfolioCourses2 жыл бұрын
Yes, it will work with non predefined words. :-)
@Mr_wisk2 жыл бұрын
@@PortfolioCourses ty i got it to work after some adjusting this helped a lot
@PortfolioCourses2 жыл бұрын
@@Mr_wisk Awesome, I'm glad to hear that! 😀
@mehedihasan_5267 Жыл бұрын
#include 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'){ word++;} i++; break; } i++; } printf("%d",word); }
@PortfolioCourses Жыл бұрын
This looks like it should be able to solve the problem OK Mehedi. :-)