Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define wielkosc 1001
- int isletter(char c)
- {
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
- {
- return 1;
- }
- return 0;
- }
- int stringlength(const char *str)
- {
- for (int i = 0; ; i++)
- {
- if (str[i] == '\0')
- {
- return i;
- }
- }
- }
- int main()
- {
- char str[wielkosc] = { '\0' };
- printf("Podaj wyrazenie : ");
- fgets(str, wielkosc, stdin);
- str[stringlength(str)] = '\0';
- int dlugosc = stringlength(str) - 1;
- int words = 0;
- int readingWord = 0;
- for (int i = 0; i < dlugosc; ++i)
- {
- if (readingWord == 0 && isletter(str[i]))
- {
- words++;
- readingWord = 1;
- }
- else if (readingWord == 1 && !isletter(str[i]))
- {
- readingWord = 0;
- }
- }
- printf("%d", words);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement