Question

In: Computer Science

Write a C program, called reverse, using standard I/O functions, to take a file as input...

Write a C program, called reverse, using standard I/O functions, to take a file as input then copies it to another file in reverse order. That is, the last byte becomes the first, the byte just before the last one becomes the second, etc. The program call should look like: reverse fileIn fileOut

Solutions

Expert Solution

C PROGRAM

#include<stdio.h>

// implement command line arguments
int main(int argc,char *argv[])
{
   FILE *fp1,*fp2; // create two file pointers
  
   int i=0,cnt; // declare integer variable i and cnt
  
   if(argc<3) // check arguments
   {
       // display this message and terminate
       printf("Error: Invalid Arguments");
       return -1;
   }
  
   fp1=fopen(argv[1],"r"); // open file of first argument in read mode
   fp2=fopen(argv[2],"w"); // open file of second argument in write mode
  
   if(fp1==NULL) // check the read file is not correct
   {
       // then, display this message and terminate
       printf("\n%s File can not be opend..\n",argv[1]);
       return -1;
   }
  
   fseek(fp1,0,SEEK_END); // set file pointer at end of file
   cnt=ftell(fp1); // count the size of file
  
   while(i<cnt) // create while loop until size of file
   {
       i++; // increment by 1 of i
       fseek(fp1,-i,SEEK_END); // set file pointer 0 to end
       fprintf(fp2,"%c",fgetc(fp1)); // write each character by character into file pointer fp2
   }
   // close all files
   close(fp1);
   close(fp2);
  
  
   return 0;
}

OUTPUT

D:\>reverse filein.txt fileOut

D:\>type fileOut
elif gnitset a si sihT

PROGRAM SCREENSHOTS***PLEASE DON'T FORGET TO GIVE THUMBS UP


Related Solutions

Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
Program Language C++ How do I take lines of string from an input file, and implement...
Program Language C++ How do I take lines of string from an input file, and implement them into a stack using a double linked list? Example input, command.txt, and output file. Ex: Input.txt postfix: BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D / E+ Command.txt printList printListBackwards Output.txt List: postfix:BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D/E+ Reversed List: postfix:AB-CF*-D/E+ postfix:AB-C-D/ postfix:FE-C/B*A+ prefix:+A*B/C-EF postfix:BAC-*
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which...
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which has the following data (you’ll have to create pop.dat) AX013 1.0 BX123456 1234.56 ABNB9876152345 99999.99 The data are account numbers and balances. Account numbers are, at most 14 characters. Balances are, at most, 8 characters (no more than 99999.99). Using a loop until the end of file, read an account number and balance then write these to standard output in the following format shown...
Write a program to reverse the lines of a file and to reverse the words plus...
Write a program to reverse the lines of a file and to reverse the words plus the letter's of each word within each line using ArrayList. A file name mobydick.txt Example: Original file contains the following MOBY DICK; OR THE WHALE by Herman Melville CHAPTER 1 Loomings. Out put should be .sgnimooL 1 RETPAHC ellivleM namreH yb ELAHW EHT RO ;KCID YBOM its for java eclipse
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
((by C++ ))Write a program that will reverse the content of a Queue using the following...
((by C++ ))Write a program that will reverse the content of a Queue using the following standard queue operations. enqueue(x) : Add an item x to rear of queue. dequeue() : Remove an item from front of queue. empty() : Checks if a queue is empty or not. For reversing the queue one approach could be to store the elements of the queue in a temporary data structure in a manner such that if we re-insert the elements in the...
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the...
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the Canvas exam instructions. Name your output file “output.txt”. Ensure the program consists of a main function and at least one other function. Ensure the program will read the input file, and will output the following information to the output file as well as printing it to the screen: output the text of the file to screen output the number of words in the file...
C++ Write a program using switch-case-break that will take an input number as for example 2...
C++ Write a program using switch-case-break that will take an input number as for example 2 and based on switch it will provide various powers of 2.
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT