Advertisement
Guest User

remvocals.c

a guest
Jan 30th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<stdlib.h>
  2.  
  3. int main(int argc, char *argv[]){
  4. //Checking if the user put in correct number of arguments.
  5. if (argc != 3){
  6. printf("Invalid number of arguments.\n");
  7. exit(1);
  8. }
  9.  
  10. FILE *fp1;
  11. FILE *fp2;
  12.  
  13. fp1 = fopen(argv[1], "rb");
  14. //Checking if the file opened correctly
  15. if (fp1 == NULL){
  16. perror("fopen");
  17. exit(1);
  18. }
  19. char numbers[44];
  20. short num[2];
  21.  
  22. //Reading file
  23. //arg1 = pointer to file where read stuff is stored
  24. //arg2 = Size of the element: in this case char (size=1)
  25. //arg3 = number of elements: here 44 elements coz 44 X 1 = 44 bytes
  26. //arg4 = file name to be read
  27.  
  28. fread(numbers, sizeof(char), 44, fp1);
  29. fp2 = fopen(argv[2], "wb");
  30. fwrite(numbers, sizeof(char), 44, fp2);
  31.  
  32. size_t input1 = fread(&num[0], sizeof(short), 1, fp1);
  33. size_t input2 =fread(&num[1], sizeof(short), 1, fp1);
  34.  
  35. short new = (num[0] - num[1])/2;
  36.  
  37. fwrite(&new, sizeof(short), 1, fp2);
  38. fwrite(&new, sizeof(short), 1, fp2);
  39.  
  40. while(input1 != 0 && input2!=0){
  41. input1 =fread(&num[0], sizeof(short), 1, fp1);
  42. input2 =fread(&num[1], sizeof(short), 1, fp1);
  43. new = (num[0] - num[1])/2;
  44. fwrite(&new, sizeof(short), 1, fp2);
  45. fwrite(&new, sizeof(short), 1, fp2);
  46. }
  47. fclose(fp1);
  48. fclose(fp2);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement