Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdint.h>
- #define N 256
- uint32_t word_count(uint8_t *mas) {
- int word = 0, count = 0;
- for (int i = 0; mas[i]!='\0'; i++) {
- if (isspace(mas[i]) == 0) {
- if (word == 0) {
- count++;
- printf("sym=[%c]\n", mas[i]);
- }
- word = 1;
- } else {
- word = 0;
- }
- }
- return count;
- }
- int main(int argc, char **argv) {
- char str[N];
- printf("Input string:\n");
- fgets(str, N, stdin); //read line
- str[strlen(str) - 1] = '\0'; // delete new line symbol
- printf("str = [%s]\n", str);
- printf("word count: %d", word_count((uint8_t*)str));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement