Advertisement
sellmmaahh

OR-Izbroj Rijeci U Stringu

Aug 9th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void unos (char* rijec, int vel)
  6. {
  7.     int i=0;
  8.     char c;
  9.     do
  10.     {
  11.         c=getchar();
  12.         rijec[i]=c;
  13.         i++;
  14.     }
  15.     while (c!='\n' && i<vel);
  16.     rijec[i-1]='\0';
  17. }
  18.  
  19. int br_rijeci (char* string)
  20. {  char *poc=string;
  21.     int brojac=0;
  22.     while (*poc!='\0')
  23.     {
  24.         if ((tolower(*poc)>='a' && tolower(*poc)<='z') && poc==string || *(poc-1)==' ')
  25.             {
  26.                 while ((tolower(*poc)>='a' && tolower(*poc)<='z'))
  27.                     poc++;
  28.                 if (*poc==' ' || *poc=='\0')
  29.                     brojac++;
  30.  
  31.            }
  32.        else poc++;
  33.     }
  34.     return brojac;
  35. }
  36. int main ()
  37. {
  38.     char rijec[100];
  39.     printf("Unesite recenicu sa max 100 znakova: ");
  40.     unos(rijec,100);
  41.     printf("Broj rijeci u recenici: %d", br_rijeci(rijec));
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement