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...
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 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...
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...
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.
Done in C++, Write a program to read the input file, shown below and write out...
Done in C++, Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets 6 Philadelphia 31, Tampa Bay 20 Green Bay 19,...
Write a C program to find out the number of words in an input text file...
Write a C program to find out the number of words in an input text file (in.txt). Also, make a copy of the input file. Solve in C programming.
Write a C program that opens a file called "numbers.txt" in writing mode. The program should...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should then read floating point numbers from the keyboard, and write these lines to the opened file one per line, stopping when the number 0 is entered. Your program should check to make sure that the file was opened successfully, and terminate if it was not.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT