Advertisement
sellmmaahh

broj rijeci u stringu

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