Guest User

Untitled

a guest
Oct 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char **argv) {
  5. FILE *fp;
  6. char line1[128], line2[128];
  7. fpos_t pos;
  8.  
  9. if(argc < 2){
  10. printf("Usage : %s <file>", argv[0]);
  11. exit(0);
  12. }
  13. fp = fopen(argv[1], "r+");
  14. if (fp == NULL) {
  15. fprintf(stderr, "Cannot open file %s\n", argv[1]);
  16. return 1;
  17. }
  18.  
  19. while (fgetpos(fp, &pos) == 0 &&
  20. fgets(line1, sizeof line1, fp) != NULL &&
  21. fgets(line2, sizeof line2, fp) != NULL) {
  22.  
  23. fsetpos(fp, &pos);
  24. fputs(line2, fp);
  25. fputs(line1, fp);
  26. fflush(fp);
  27. }
  28.  
  29. fclose(fp);
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment