C++ :: How To Reverse A Text File
Dec 26, 2013If we have a text file containing the string: abc, how to reverse it to be cba using file open modes (ios::app, ios::ate, ios::binary, ios::trunc, ios::in and ios::out)?
View 19 RepliesIf we have a text file containing the string: abc, how to reverse it to be cba using file open modes (ios::app, ios::ate, ios::binary, ios::trunc, ios::in and ios::out)?
View 19 RepliesC program to count the number of lines in a text file and reverse the contents in the file to write in an output file.
ex :
input
one
two
three
output:
three
two
one
Code software that, from an original text file, generate another file with the text content in upper case.For exemple:
entrence:
luke
tom
alex
outings:
LUKE
TOM
ALEX
My code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
[code]....
I am trying to write a function to reverse a wav file. The idea is to copy the header as it is from the begening of the input.wav file to the beginning of the output.wav file. After that i have to take count number of bytes(count = numberChannels * bitsPerSample in the wav i use this is 2*16= 32 bits, 32/8 = 4 bytes). With this code i am trying to copy the header( that's working fine) and then copy 10 samples from the end and put them to the output.wav file(after header not at the beginning).
This is the content of the input file:
The last 4 bytes of the header are bolded.
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 00 10 00 10
ff 00 10 00 00 10 00 10 00 00 ff 10 10 10 00 10
00 00 00 10 10 10 10 00 00 00 10 00 10 00 10 ff
00 10 00 00 10 00 ff 00
This is the content of the output file it suppose to have in my example
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 10 00 ff 00
00 10 00 00 10 00 10 ff 00 00 10 00 10 10 10 00
00 00 00 10 10 10 00 10 00 00 ff 10 00 10 00 10
ff 00 10 00
Code:
void reverse(char **array) {
int i=0;
word numberChannels;//word is unsigned short int , byte is unsigned char
word bitsPerSample;
[Code] .....
The problem is that (having in mind per sample is 4 bytes) instead of copying 40 bytes it just copies 20
works fine without the for loop.... if i use for loop...it doesnt give the output...
Code: #include<iostream>
#include<conio.h>
#include<fstream>
[Code]....
The next step for my project is to take data from a file, and create a new file with the same data, but in reverse order. If a file has the following values:
1
2
3
4
5
The program should create a new file with the following values:
5
4
3
2
1
Seems pretty straight forward, yet I am hitting a snag when I try to compile my program:
Code:
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
[Code] ....
The following errors occur when I try to compile the fore mentioned code:
intrev.c: In function 'main':
intrev.c:25: warning: unused variable 'out'
intrev.c: At top level:
intrev.c:39: error: expected identifier or '(' before 'while'
[Code] .....
Now I am not concerned with "unused variable 'out'" as it is used, just in a for loop. Is this a problem?
I'm not entirely sure why it's giving me the error at line 39. I've gone over this a couple times and it doesn't look like I've missed any methods which need to be closed. Maybe I've missed something?
I'm also not sure why I am getting an error when I try to close the opened files. I've done this before in the same manner, but without errors. Not sure why I am now, but my guess is that it has something to do with the error on line 39.
Need to correct the errors. i've done so far.
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main() {
ifstream fin; char ch; int size=0;
[Code]...
1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food
2. Modify Food
3. Delete Food
4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
I want to make a program that opens a text file and checks the usernames listed in the text files to see if the names are registered on a site such as twitter. How easy would this be to make, what things would I need to know?
View 4 Replies View RelatedI am trying to get text file and read only first 100 lines of the text content using c/c++. how can i do it?
is it something like string line;
getline(stream,line);
??
I have a huge text file in following format:
{Bunch of text
.
.
}
[Code].....
I want to extract Text1, Text2, Text3, Text4,..., Text600 in the output file. How can i achieve this?
/* BTW, I am not getting my homework done here. I am an ex-programmer, who has now moved to marketing for some time now, and today, I encountered this problem, which I believe can be solved easily through programming. */
i want to create 100 gmail accounts instantaneously....what i want from you guys is i have written a program that create a text file i want that once i give the program the imput of 1 it should delete the first 3 lines from the file i.e. the first account details coz that is already been created and shift the rest of it 3 lines upwards after that i'll write a javascript that will automatically fill and create the accounts with those names in web browser.....my lil program is here:
#‎include <stdio.h>
#include <conio.h>
main()
[Code]....
I have a text file called (Test.txt) with the following text:
This is line one
This is line two
This is line three
How do I go about writing a program that will print a line of text (e.g. "This in line two" on the console screen?
All I can seem to do is display the entire text file.
I have this code for a computer project... (store management) but the character strings are not copied on text file..
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()
[Code] .....
Now when i run the program, it gives a error :::
ERROR
address 0x0
How can i write these strings to the text file?
The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.
How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?
If "Y" Than Inputs Are Taken From Next Line Else Input Ends.
But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.
Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){
[Code].....
I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpin=fopen("namesIN.txt", "r");
FILE *fpout=fopen("emailOUT.txt", "a");
char first[20],last[20],inbuff[1500];
[Code]...
I am writing a simple file/text parser to read a config file for some code I am working on. It's dead simple and not particularly smart but it should get the job done. The code reads a config file:
Code:
readlength=2500000
start=0
finish=25000000
cutoff=20000
samplingfreq=250000
poles=10
filterpadding=500
}
[code]....
Here is where it gets wierd. You'll notice that there is an unused variable (filepath) in the config struct. This variable is not referenced or used anywhere in the code, ever. Yet if I comment out the declaration of char filepath[1024], the code segfaults partway through the read_config() function.
My best guess is that there is a buffer overflow elsewhere and it just so happens that the memory allocated for filepath happened to be there to catch it up until now, but I can't work out where it might be happening. With the declaration commented out, the read_config() function gets as far as reading the "padding" variable before it crashes. Yet when the declaration is there, then all the variabled are read correctly and everything seems to work.
I need to create a program which could create text files of the bits stored in avi file/binary file. My first requirement is to show 0s and 1s in the text representation . My second requirement is to create an avi file from this text file. I have tried few codings but either they give me error or they not playing the reconverted binary files.
View 6 Replies View RelatedI have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?
I want to sort the lines based on the FIRST value.
Example text file contents:
values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324
Output: Text file containing
2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43
It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?
I have a program I have to do that counts the number of words in a text file. I have tried the code on 2 computers now since my programming teacher told me the code was fine. Here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream infile;
infile.open("tj.text" , ios::in);
[Code] .....
I have a very big xml file. I read it using by xmlReader. I have problem when i reach to next line:
<title>Abasia<nemod>(-astasia) (hysterical)</nemod></title>
How I can read all that content. I have to have next string at the end: "Abasia (-astasia) (hysterical)".
I tried to use ReadElementContentAsString() for all elements, but elements like this has exception, because it has child element.
I'm having a little problem with std:fstream - in my program, the user selects the location of a file which I want to remember. So, I have something like this:
Code: std::string fileLocation;
//Code here creates an 'open file' dialog box which lets the user choose which file to open.
//The string 'fileLocation' now contains the path to the chosen file.
std::ofstream prefs("prefs.txt");
if (prefs.is_open())
{
prefs << fileLocation;
prefs.close();
}
This works fine if the file chosen is in the same directory as the program, however, if they try to choose a directory outside of where the program is kept, it saves the text file into that directory instead of the same one as the program. So, it looks like outputting a directory into an ofstream actually changes the location to which the file is saved.
Is there a way to save the file directory to a text file using ofstream and still have the text file save in the same directory as the program?
Can i edit records stored in file without rewriting whole file again .?
View 1 Replies View RelatedI just wrote a program for Huffman Encoding, where I take a text file, encode it in the form of 0's and 1's, and save that as another text file. However, this does not solve my purpose as it is taking even more space.
So I want to know how do I convert a text file containing these 0'S & 1's to a binary format.
Here is my program:
#include <stdio.h>
#include <string.h>
#include<fstream>
#include<string>
#include<iostream>
using namespace std;
typedef struct node_t {
struct node_t *left, *right;
int freq;
char c;
[Code]...
C++ code that will take the existing comments from a arbitrary C file, and store those files in a text document?
View 4 Replies View RelatedI want to convert a text file into binary file. I should create the text file by myself. I also use a structure for the components:
struct Data
{
int num;
char name[30];
};
I write information in the text file like this:
Data d;
cin >> d.num >> d.name;
fstream file("Name.txt");
file << d.num << d.name << '
';
If I have entered:
3 Steve
is easy to get this data. I just make another variables and get the data in them:
int num2;
char name2[30];
file >> num2 >> name2;
And everything is done. But what if I have this:
cin >> d.num;
cin.getline(d.name, 100);
file << d.num << d.name;
and the input is:
5 Steve Brown
I can get the number easy like before but how can I get the whole name? If I use:
int num2;
file >> num2;
char a[30];
file >> a;
I get only the first name "Steve". Can I get somehow and the second name in the same variable?