Essam_khames

Untitled

Nov 29th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define MAX_LENGHT 257
  6. int main()
  7. {
  8. int i=0,j=0,k=0,s=0;
  9. char str[MAX_LENGHT];
  10. fgets(str,MAX_LENGHT,stdin);
  11. while(str[i]=='\t'||str[i]==' '){
  12. i++;
  13. }
  14. while(str[i]!='\0'){
  15. if(str[0]==' '||str[0]=='\t'){
  16. if((str[i]!=' ')&&(str[i]!='\t')){
  17. j=i-1;
  18. s=0;
  19. while(((str[j]!='\t')&&(str[j]!=' ')&&(str[j]!='\0'))){
  20. j++;
  21. s++;
  22. }
  23. if(((str[j]=='\t')||(str[j]==' ')||(str[j]=='\0'))){
  24. k++;
  25. i++;
  26. }}}
  27.  
  28. else{
  29. if((str[i]!=' ')&&(str[i]!='\t')){
  30. j=i;
  31. s=0;
  32. while(((str[j]!='\t')&&(str[j]!=' ')&&(str[j]!='\0'))){
  33. j++;
  34. s++;
  35. }
  36. if(((str[j]=='\t')||(str[j]==' ')||(str[j]=='\0'))){
  37. k++;}
  38. }
  39. else{
  40. i++;
  41. }
  42. }
  43.  
  44. i=i+s;
  45. }
  46. printf("%d words",k);
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment