Advertisement
boyan16-z

The longest word

Mar 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char str[255];
  8. int count = 0, i, id, max = 0;
  9. printf("Insert: ");
  10. gets_s(str);
  11. for (i = 0; i < strlen(str) - 1; i++) {
  12. if (str[i] != ' ') count += 1;
  13. else {
  14. if (count > max) {
  15. max = count;
  16. id = i - count;
  17. }
  18. count = 0;
  19. }
  20. }
  21. max += id;
  22. for (i = id; i < max; i++) putchar(str[i]);
  23. printf("\n");
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement