Question: Show me the steps to solve % % writefile file _ tools.c #include file _ tools.h #include size _ t read _ data (
Show me the steps to solve writefile filetools.c
#include "filetools.h
#include
sizet readdatachar filename, unsigned char data
When we open a file, we keep that location
as a file pointer, so declare one.
FILE fp;
Open the file for reading.
fp fopenfilenamer;
Go to the end of the file.
fseekfpL SEEKEND;
ftell says where we are in the file. Since we went to the
end, this will tell us how many bytes are in the file.
sizet filesize ftellfp;
Go back to the beginning.
fseekfpL SEEKSET;
Now, we know how many bytes we need. Ask for that much space,
and store the address.
data mallocfilesize;
Read the data and store it in our location.
freaddata filesize, fp;
Close the file.
fclosefp;
Return the number of bytes we found.
return filesize;
sizet writedatachar filename, sizet datasize, unsigned char data
Open the file for writing.
FILE fp fopenfilenamew;
if fp NULL
perrorFailed to open file for writing";
return ;
Write the data to the file.
sizet written fwritedata datasize, fp;
Close the file.
fclosefp;
Return the number of bytes written.
return written;
writefile reversal.c
#include
#include
#include "filetools.h
int mainint argc, char argv
Create a variable that will hold the address of where
our data is loaded into.
unsigned char data;
Load the data into that area and get back the number of
bytes read.
sizet filesize readdatasharedaudiobackwardswav", &data;
printfSize: lu bytes.
filesize;
Write the data to a new file.
sizet writtensize writedatasharedaudioforwardswav", filesize, data;
printfWritten Size: lu bytes.
writtensize;
free the allocated memory
freedata;
return ;
writefile reversal.c
#include
#include
#include "filetools.h
int mainint argc, char argv
unsigned char data;
sizet filesize readdatasharedaudiobackwardswav", &data;
printfSize: lu bytes.
filesize;
printfFirst four bytes: c c c c data data data data;
printf
;
return ;
writefile reversal.c
#include
#include
#include "filetools.h
int mainint argc, char argv
unsigned char data;
sizet filesize readdatasharedaudiobackwardswav", &data;
printfSize: lu bytes.
filesize;
printfFirst four bytes: x x x x data data data data;
printf
;
return ;
writefile reversal.c
#include
#include
#include "filetools.h
int mainint argc, char argv
unsigned char data;
sizet filesize readdatasharedaudiobackwardswav", &data;
printfSize: lu bytes.
filesize;
printfSample rate: d data;
printf
;
return ;
writefile reversal.c
#include
#include
#include "filetools.h
int mainint argc, char argv
unsigned char data;
sizet filesize readdatasharedaudiobackwardswav", &data;
printfSize: lu bytes.
filesize;
int value int&data;
printfSample rate: d value;
printf
;
return ;
Ok Now what?
Well, now that we understand more about working with data in C let's do something cool!
I want you to make a program that will get information about a wav file then modify the file so that it will play backward. We can't simply reverse all the bytes in the file though, as some are metadata, and others are samples that are more than one byte long. What we need to do is
copy the metadata
reverse the samples not the bytes
Let's say that you have the following samples:
If we wanted this audio to play backward, we would need to rewrite it so that it looks like this:
The first bytes of the file are the metadata. You can copy the metadata without modifying it to the new file. Then, you need to copy each sample from the old file to the new one, in reverse. The wave file I have given you is very easy to work with; each sample is bits bytes and there is only one channel. The samples start at byte number Make sure you output your file to a different name. Use the code in the above cell to play your sound file after you reverse it If you did it correctly, you will be able to hear words and you might recognize the voice
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
