Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. char str[256];
  6. char str2[256];
  7. char word[256];
  8. char str3[256];
  9. int inWord = 0,count=0;
  10. int maxLen = 0 ,minLen=256;
  11. while (fgets(str, 255, stdin) != NULL)
  12. {
  13. int j = 0;
  14. for (int i = 0; str[i]; i++)
  15. {
  16. if (inWord == 0)
  17. {
  18. if (str[i] != ' ' && str[i] != '\n' && str[i] != '\t')
  19. {
  20. inWord = 1;
  21. if (strlen(str) > maxLen)
  22. {
  23. maxLen = strlen(str);
  24. strcpy(str2, str);
  25. }
  26. if (strlen(str) < minLen)
  27. {
  28. minLen = strlen(str);
  29. strcpy(str3, str);
  30. }
  31. word[j++] = str[i];
  32. }
  33. }
  34. else
  35. {
  36. if (str[i] != ' ' && str[i] != '\n' && str[i] != '\t')
  37. {
  38. word[j++] = str[i];
  39. if (strlen(str) > maxLen)
  40. {
  41. printf("word with max length changed\n");
  42. maxLen = strlen(str);
  43. strcpy(str2, str);
  44. }
  45. if (strlen(str) < minLen)
  46. {
  47. printf("word with min length changed\n");
  48. minLen = strlen(str);
  49. strcpy(str3, str);
  50. }
  51. }
  52. else
  53. {
  54. inWord = 0;
  55. word[j] = '\0';
  56. j = 0;
  57. count++;
  58. }
  59. }
  60. }
  61. printf("Word:%s\n", word);
  62. printf("Max Length word:%s", str2);
  63. printf("Min Length word:%s", str3);
  64. printf("Word Count:%d\n", count);
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement