Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int WordsCounter(char* str);
- int main()
- {
- char str[100] = { 0 };
- int wordCount = 0;
- puts("======== This program is Word Counter. ========");
- gets(str);
- wordCount = WordsCounter(str);
- printf("\n[Your string has '%d' words.]\n\n", wordCount);
- return 0;
- }
- int WordsCounter(char* str){
- char strBuff[50] = { 0 };
- int wordCnt = 0;
- for (int i = 0; i < sizeof(*str); i++) {
- if (str[i] != '.')
- strcat(strBuff, str[i]);
- if (str[i] == ' ') {
- printf("%s\n", strBuff);
- for (int j=0;j<sizeof(strBuff);j++)
- strBuff[j] = '\0';
- wordCnt += 1;
- }
- }
- return wordCnt;
- }
Add Comment
Please, Sign In to add comment