Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C code for the tasks below, run it and make sure the results are correct.

ID: 3821691 • Letter: W

Question

Write C code for the tasks below, run it and make sure the results are correct. Use CodeBlocks or an alternative development environment of your choice. Print out your code and your results for all tasks, and submit a hard copy in class. (To capture your results in the console window, you may want to use Alt-PrintScreen or a similar key in your system and then paste up the picture in a word processor, along with the code.) A random subset of problems will be graded. It is, however, your responsibility to solve all problems in all assigned homework. Tip: if you are working under Windows, click on the tiny icon at the top left corner of the console window to change the default appearance of this window, I would recommend changing the background to white for better visibility and to conserve ink when printing. (See example nearby.) 1. File my_text. txt contains several lines of English text, up to 80 characters per line. The number of lines may vary. Reverse each line and write the reversed text into file my_text_reversed.txt as in the example below.

Explanation / Answer

#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
long line_count(FILE *);
int main(int argc, char *argv[])
{
FILE *fp1,*fp2;
char ch, ch1;
int i;
long lc = 0;
if(fp1 = fopen(argv[1],"r"))
{
printf(" File Opened");
fp2 = fopen(argv[2],"w");
lc = line_count(fp1);
fseek(fp1, -1L, 2);
printf(" Number of characters to be copied",ftell(fp1));
while(lc)
{
ch = fgetc(fp1);
fputc(ch, fp2);
fseek(fp1, -2L, 1);
lc--;
}
printf(" File Copied");
}
else
{
perror("Error Occurred");
}
fclose(fp1);
fclose(fp2);
return 0;
}
long line_count(FILE *f)
{
fseek(f, -1L,2);
long position = ftell(f);
return position;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote