Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. int main(){
  5.  
  6. int rc = 0;
  7.  
  8. FILE *inc = NULL;
  9. FILE *out = NULL;
  10.  
  11. char *incname = "./some.wav";
  12. char *outname = "./out.wav";
  13.  
  14. if( access(incname, R_OK) == -1) {
  15. printf("E: no readable file '%s' was found\n", incname);
  16. rc = 1;
  17. goto safe_fail;
  18. }
  19.  
  20. if( access(outname, F_OK) != -1) {
  21. printf("E: file '%s' already exists\n", outname);
  22. rc = 2;
  23. goto safe_fail;
  24. }
  25.  
  26. inc = fopen(incname, "rb");
  27.  
  28. int seekrc = fseek(inc, 0L, SEEK_END);
  29. if(seekrc != 0){
  30. printf("E: seek on '%s' failed\n", incname);
  31. rc = seekrc;
  32. goto safe_fail;
  33. }
  34.  
  35. long inclen = ftell(inc);
  36. rewind(inc);
  37.  
  38. seekrc = fseek(inc, 44L, SEEK_SET);
  39. if(seekrc != 0){
  40. printf("E: seek on '%s' failed\n", incname);
  41. rc = seekrc;
  42. goto safe_fail;
  43. }
  44.  
  45. printf("I: len of '%s' is %ldB\n", incname, inclen);
  46.  
  47. out = fopen(outname, "wb");
  48.  
  49. int count = 0;
  50. int getrc = 0;
  51. while(getrc != EOF){
  52.  
  53. getrc = fgetc(inc);
  54.  
  55. if(count < 45){
  56. fputc(getrc, out);
  57. count++;
  58. continue;
  59. }
  60.  
  61. fputc(getrc - 0, out);
  62.  
  63. }
  64.  
  65. safe_fail:
  66.  
  67. if (inc != NULL) fclose(inc);
  68. if (out != NULL) fclose(out);
  69.  
  70. return rc;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement