Question: Show me the steps to solve Now, complete the code for the write _ data function. You can write your code in the same box
Show me the steps to solve Now, complete the code for the writedata function. You can write your code in the same box above where I left the function stub the return in the writedata function You will need to look up and learn how to use the fwrite function.
This function is given a filename, a number specifying the number of bytes to write, and a string of bytes. Why must we pass the number of bytes as a parameter? Why can't we simply find out the length from the string? Well, C doesn't have strings. What we have is a char which is the address where the "string" starts. We can't ask the address how long it is it is just an address!
Modify the main function above so that it reads a file's contents into memory and then writes out a new file with the contents. Ensure that the two files are exactly the same byte for byte. To do this, you may want to check the size of the files, or use the hexdump command. This command will print out the contents of a file in hex. For instance:
c c f f c Hello world! I
c f f d e a love computers..
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
return ;
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;
printf
;
return ;
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
