Question

Reverse the order of characters in a "text file". For example, computer becomes retupmoc Text file...

Reverse the order of characters in a "text file". For example, computer becomes

retupmoc

Text file have this String "Computer"..

write on other file String "retupmoc".

Write this in C++..

Homework Answers

Answer #1

#include <iostream>
#include <stdlib.h>

using namespace std;

//method to reverse the string
string reverseString(string str)
{
int size = str.size();
char revStr[1000];
int i=0;
  
while(str[i] != '\0' && str[i] != '\n')
{
size--;
revStr[i++] = tolower(str[size]);
}
revStr[i] = '\0';

return revStr;
}

int main(void)
{
//array declaration
char c[1000];
FILE *fptr, *fptr1;
if ((fptr = fopen("data.txt", "r")) == NULL)
exit(1);

fscanf(fptr, "%[^\n]", c);
fclose(fptr);
  
//function calling
string revStr = reverseString(c);
  
if((fptr1 = fopen("result.txt", "w")) == NULL)
exit(1);
  
int i=0;
//write to the file
while(revStr[i] != '\0' && revStr[i] != '\n')
{
fprintf(fptr1, "%c", revStr[i++]);
}
  
//close the file
fclose(fptr1);
  
return 0;
}

INPUT:

data.txt

OUTPUT:

result.txt

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text editor of your choice). This program will “explode” a String into an array of characters (char[]), and then print out the array. The String comes from the first command-line argument. Example output with the command-line argument foo is below: f o o --------------------------------------------------------------------- public class StringExplode { // TODO - write your code below this comment. // You will need to write a method...
Write an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
2. Define a function write_to_file(filename, text) that takes in a filename (a string) and a list...
2. Define a function write_to_file(filename, text) that takes in a filename (a string) and a list of strings as arguments. Your function will open a file and write the contents of text onto the file. Each element in the list represents a separate line in the file, without newline characters. You will have to add the newline characters in yourself. This function does not return or print anything; it will create a new file.
Attached is a text file containing lots of randomly generated numbers in no particular order. Write...
Attached is a text file containing lots of randomly generated numbers in no particular order. Write a program that can open that file, sort the numbers from least to greatest, and display them in sorted order on the screen. The name of the text file is; numbers_fall2020.txt Please solve using C++ Thanks!
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling to check if the file exists before attempting to open it. Read and print each string to the console. Next modify each word such at the first letter in each word is uppercase and all other letters are lowercase. Display the modified word on the console. Creating a text file: Open up Notepad and type in the following words. Save the file as collectionOfWords.txt...
This is for C++ A string is a palindrome if reverse of the string is same...
This is for C++ A string is a palindrome if reverse of the string is same as the original string. For example, “abba” is palindrome, but “abbc” is not palindrome. Basically a string with a plane of symmetry in the middle of it is considered a palindrome. For example, the following strings are palindromic: "abbbbba", "abba", "abbcbba", "a", etc. For this problem, you have an input string consisting of both lowercase or uppercase characters. You are allowed to pick and...
Create a vector of 50 characters PRG from A to Z. Sort the list in reverse...
Create a vector of 50 characters PRG from A to Z. Sort the list in reverse order (from Z to A). Please use c++. Please use #include.
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
Huffman Codes: You are give a text file containing only the characters {a,b,c,d,e,f}. Let F(x) denote...
Huffman Codes: You are give a text file containing only the characters {a,b,c,d,e,f}. Let F(x) denote the frequency of a character x. Suppose that: F(a) = 13, F(b) = 4, F(c) = 6, F(d) = 17, F(e) = 2, and F(f) = 11. Give a Huffman code for the above set of frequencies, i.e. specify the binary encoding for each of the six characters.
Write a program that takes a string of characters (including spaces) as input, computes the frequency...
Write a program that takes a string of characters (including spaces) as input, computes the frequency of each character, sorts them by frequency, and outputs the Huffman code for each character.   When you are writing your program, you should first test it on a string of 7 characters, so you can check it. PLEASE NOTE: Your program must work for any text that has upper and lower case letters digits 0 - 9, commas, periods, and spaces. Please submit the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT