Advertisement
thelost

Untitled

Jan 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int comp (const char *i, const char *j)
  5. {
  6. char ch=i[strlen(i)-1];
  7. char ch1=j[strlen(j)-1];
  8. int a=ch;
  9. int b=ch1;
  10. return a - b;
  11. }
  12. int main() {
  13. int n = 0;
  14. FILE* fp = fopen("input.txt", "r");
  15. fscanf(fp, "%d", &n);
  16. char** a = (char**)calloc(n, sizeof(char*));
  17. int count = 0;
  18. while (count < n)
  19. {
  20. a[count]=(char*) calloc (100,sizeof(char));
  21. fscanf(fp, "%s", a[count]);
  22. ++count;
  23. }
  24. fclose(fp);
  25. fp = fopen("output.txt", "w");
  26. qsort(a, n, sizeof (char), (int(*) (const void *, const void *)) comp);
  27. for (int i = 0; i < n ; ++i)
  28. {
  29. if (i == n - 1) fprintf(fp, "%s\n", a[i]);
  30. else fprintf(fp, "%s ", a[i]);
  31. }
  32. fclose(fp);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement