Advertisement
Guest User

rewrite-header

a guest
Oct 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. //rewrites the header of a bmp file
  2. #include <stdio.h>
  3. int main(int argc, char* argv[]) {
  4. unsigned char bufferOriginal[54];//wil store the header of the original file
  5.  
  6. printf("num of cmd args: %d", argc);
  7. for(int i = 0; i < argc; i++) {
  8. printf("%d arg: %s \n", i, argv[i]);
  9. }
  10.  
  11.  
  12.  
  13. FILE *ptrOriginal = fopen(argv[1], "rb");//pointer to the original file
  14. FILE *ptrNew = fopen(argv[2], "r+b");//pointer to the file that we overwrite
  15.  
  16. if(ptrOriginal == NULL) {
  17. printf("couldn't open first file, exiting\n");
  18. return 0;
  19. }
  20.  
  21. if(ptrNew == NULL) {
  22. printf("couldn't open second file, exiting\n");
  23. return 0;
  24. }
  25.  
  26. fread(bufferOriginal, sizeof(bufferOriginal), 1, ptrOriginal);//saving the original header in the bufferOriginal
  27.  
  28. printf("copied the original header\n");
  29.  
  30. fseek(ptrNew, 0, SEEK_SET);//sets the position to the beginning of the file
  31.  
  32. printf("writing the header to the new file\n");
  33.  
  34. fwrite(bufferOriginal, sizeof(bufferOriginal), sizeof(bufferOriginal), ptrNew);//writing first 54 bytes from the orignal file to new file
  35. printf("done.\n");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement