Hi guys I have spent a couple days trying to figure how to create these two programs with little luck can you guys please show me how it can be written I just can't figure out how to use these functions: fread, fclose, fseek, ect.
Q1) Write a program to delete the sixth line in a file. Do not change
the sixth line to a blank line; delete it completely.
*** this one I was able to replace the file with what I wanted but realized it needs to be deleted ***
Q2) Write a function that deletes the last line of any file.
*** this one didn't even know where to start ***
I already have lost the marks for these two questions but looking to see how they can be written as I need the practice for my exam thanks to anyone who can help
Since we don't write peoples programs for them, why don't you show us what you've written, that didn't work as intended, and some of us here could probably point you in the right direction of having a correctly working program.
As whitenite1 said we don't write peoples programs for them but if i believe you, i solved your Q1 because You said you already tried it for Q1 but for Q2 i have only idea and you have to implement it. So the idea is
1. Get the last line of the file.
2. Put the line in the function "delLine".
#include <stdio.h>
int main()
{
FILE * pFile;
if ((pFile = fopen ("Q4.txt", "r")) == NULL)
{
printf("File could not be opened\n");
}
pFile = fopen ("Q4.txt","w");
if (pFile != NULL)
{
fputs ("first line\nsecond line\nthird line\nfourth line\nfifth line\n\n",pFile);
fclose (pFile);
}
}
I found out after I had handed it in that I am just replacing the file and the line was suppose to be deleted by reading line by line and printing them out as they were read and deleting the 6th line ... I was unsuccessful at this