fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <locale.h>
  6. #define N 1000
  7. #define M 1000
  8. int main()
  9. {
  10. char arr[1000][M] = { 0 };
  11. char str[N], result[N];
  12. char sp[] = " ";
  13. //Удалил переменную tmp и все что с ней связано, т.к. бесполезная
  14. int count = 0, max = 0, maxI = 0;
  15.  
  16. fgets(str, N - 1, stdin);
  17.  
  18. char* token = strtok(str, sp);
  19. int i = 0;
  20. while (token != NULL)
  21. {
  22. count = strlen(token);
  23. //Тут я думаю логичней использовать strcpy а не strcat
  24. strcpy(arr[i], token);
  25.  
  26. if (count > max) {
  27. max = count;
  28. maxI = i;
  29. }
  30.  
  31. ++i;
  32. token = strtok(NULL, sp);
  33. }
  34.  
  35. char tmp_str[M];
  36. strcpy(tmp_str, arr[0]);
  37. strcpy(arr[0], arr[maxI]);
  38. strcpy(arr[maxI], tmp_str);
  39.  
  40. for (int j = 0; j < i; j++)
  41. printf("%s%s", arr[j], j < i - 1 ? " " : "");
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 4984KB
stdin
Hi here, Man !!! Longer
stdout
Longer here, Man !!! Hi