C++ :: Replace Some Elements In Text File?

Nov 4, 2014

I have a text file, like that:

(A1*
*
*
*A1)
*
(AM-MNR*AM-MNR)
(V*V)
(C-A1*
*
*
*
C-A1)

Now, I would like to replace some elements, follow the rule:

-(A1* ---> B- A1
- characters "*" following is replace by I-A1
- *A1) ---> I- A1

The output like that:

B- A1
I- A1
I- A1
I- A1
*
B-AM-MNR
(V*V)
B-C-A1
I-C-A1
I-C-A1
I-C-A1
I-C-A1

How can I do now?

My text file have 220 663 lines and 858 995 characters (I used Linux commands : wc to count them. If I use array to store data, I think it's too large array. But if use fstream, I dont know to access each element in stream to compare and replace. I dont know How many labels such as: A1, C- A1, AM- MNR... which I have to replace.

View 1 Replies


ADVERTISEMENT

C++ :: How To Find And Replace Info In Text File

Jul 1, 2014

I have a program that gives the user the option to create an employee ID, name, address and so on. It also has the option to search employee by employee ID.

What I want to know is how to add and replace employee info. For example employee changes address. Also how to delete employee information from text file.

Here's my code:

//This program uses file input and output for an employee information system.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile
ofstream outFile;

[Code] ....

View 1 Replies View Related

C :: Search Table And Replace Values In Text File

Feb 3, 2015

I have to develop a C program that reads a very complex txt file (output of a calculation code, so full of mixed text and numerical tables), search for a specific table in it and individuate/print or replace a specific value with assigned position in the table.

View 2 Replies View Related

C++ :: Find And Replace Employee Information In Text File

Jul 15, 2014

How to search for a word in a text file and replace it with a new one. Such as employee address, or first name, etc.

Here's my code:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile

[Code] ....

It is under choice 3, most of my program runs correctly but I am just stuck at this part.

View 3 Replies View Related

C++ ::  pass Parameters From Other Application To Replace String Within Text File Before Execute Registry Merge

Jan 27, 2014

I'm creating simple console application using Code::Blocks to allow me to pass parameters from other application to replace string within text/registry file before execute the registry merge. Passing parameters to console already success. Now I only have problem with reading file. Example of first line in the registry file is as below.

Windows Registry Editor Version 5.00

However when read into string and output to console using 'cout', it will be show as below with spaces in between.

W i n d o w s R e g i s t r y E d i t o r V e r s i o n 5 . 0 0

Below is my code.

ifstream f("install.reg");
string s((istreambuf_iterator<char>(f)), istreambuf_iterator<char>());
cout << s;

View 6 Replies View Related

C :: Replace Repeated Elements Within 2D (10x10) Int Array

Mar 20, 2014

I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.

Code:
46 for(row=0;row<10;row++)
47 {
48 for(col=0;col<10;col++)
49 {
50 board[row][col]=rand()%4+1; //filling matrix here

[Code] .....

I know there must exist a much more elegant approach than listing out all permutations.

View 1 Replies View Related

C++ :: Find And Replace Function For Text Editor

Jan 3, 2013

I'm building a find and replace function for my text editor I'm building the function without support from the algorithm header.

The function is written like: doc.find_replace("Word_to_be_replaced", "The_word_that_is_replacing"); I find this very easy to understand replace this, with this.

find_replace will both have char * as their arguments.

The problem I'm having right now if I replace a bigger word for a smaller word how do I delete the extra characters from memory.

So if I replace "Goodbye" with "Hello" how do I delete the last two characters? So I don't print garbage code.

View 1 Replies View Related

C++ :: Integration With Word - Highlight Text And Offer Find / Replace Functionality

Sep 10, 2013

I'm undertaking a project at the moment which requires me to hook into a custom c++ application from a Java applet via JNI. The c++ application needs to communicate with MS Word and potentially other office programmes in order to highlight text and offer find/replace functionality programatically. The idea is that when the applet is launched, it will communicate with the C++ methods to hook into an open MS Word document and highlight all words that start with the letter 't' for example.

I'm concentrating on the C++ side of things first . Even some basic access to an open word document would give me a great start!

View 3 Replies View Related

C :: How To Replace A String Of A Person In A File

Mar 6, 2015

I'm having a bit of problem. I've set the string 'Absent' to all student in a file. However, I want to replace 'Absent' with 'present' when the correct ID assigned to a student is entered. In other words, 'Absent' will only change to 'Present' for a specific person at a time. I'm not sure how to implement this

View 4 Replies View Related

C/C++ :: File String Replace Algorithm?

Nov 10, 2014

I adapted the code from the following: [URL]

To replace a string in my file with another. The file contents look like the following:

abc 123 0

"abc"= The username
"123"= Their password
"0"= The amount in their bank

I want to change their bank amount.

But, it isn't working, nor is it even giving me an error code.

// When the user logs out, make changes to their bank
string strNew = std::to_string(player.bank); // String representation of the revised player bank
ifstream filein("user_accounts.txt"); // Old repository of player data
ofstream fileout("user_accounts_new"); // New repository of player data

[Code].....

View 2 Replies View Related

C/C++ :: How To Remove And Replace Some Char In A File

Jun 3, 2014

I want to remove some character in my file. too i want to replace some char to another. I know the easiest way for this job is we write final text in file. i mean we first produce sightly text then write it in file . I don't want use of temporary string.

View 3 Replies View Related

Visual C++ :: Replace Particular Line In A File

Jun 29, 2013

I want to read a file and replace a particular line in a file.

Ex:

temp.txt file contains below

FilePath1: xxxxxxxxxxxxxxxxxxxxxxxxx
FilePath2: xxxxxxxxxxxxxxxxxxxxxxxxx
FilePath3: xxxxxxxxxxxxxxxxxxxxxxxxx
Mode: 1

Here My requirement is replace the 4th line Mode: 2 instead of Mode: 1.

I was used seek method like below,

Code:
CStdioFile SaveFile;
CString strFilePath;
strFilePath = _T("C:Sara emp.txt");
if (SaveFile.Open(strFilePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite), &fileException) {

[Code] ....

The above code not working correctly.

View 14 Replies View Related

C++ :: Find / Calculate And Replace A String In A File

Feb 3, 2013

i have a text file... with example following content:

Pizza 23232
Car 44,495
Drink 3493,90494
....
..
.

and so on..

no i want to find the 44,495 in this textfile.. calculate a new value like 44,495 x 2 + 5

and write the same file as

Pizza 23232
Car 93,99
Drink 3493,90494
....
..
.

back..

View 2 Replies View Related

C++ :: Function To Replace A File With The Contents Of Another Stream

Apr 26, 2012

I have function which will replace (or create) an file with the contents of another stream. The stream could be anything. The replacement is done safely.

Code:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
int do_replace(const char *file, int stream, int cnt) {

[Code] .....

View 14 Replies View Related

C# :: How To Clear A Text Box With Old String And Replace With New String

Jan 22, 2015

I have a problem i have a textbox filled with info when the button is click but what i need to do now is when new info is place in the textbox i need the results textbox's to clear and the new info put in the textbox.

i know how to clear the textbox

txtVolume.Text = string.Empty;

But it just keeps the textbox empty.

View 5 Replies View Related

C++ :: Binary File - Replace Data At Specific Point?

Nov 28, 2014

I'm making a binary file that has 100 "empty spaces", and then I want to rewrite specific place with info, however it always writes the info at the end of the file, no matter what I try to get position before I call write() it tells me correct position...

#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

[Code].....

View 5 Replies View Related

C :: Original Text File / Generate Another File With Text Content In Upper Case

Nov 29, 2014

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]....

View 2 Replies View Related

C/C++ :: Program That Opens Text File And Checks Usernames Listed In Text Files?

Jun 5, 2014

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 Related

C++ :: Getline - Get Text File And Read Only First 100 Lines Of Text Content

May 31, 2013

I 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);

??

View 7 Replies View Related

C++ :: Filter Text Enclosed In Specific Tags From Text File?

Aug 30, 2013

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. */

View 3 Replies View Related

C/C++ :: Delete Text From File And Than Shift The Rest Of The Text Upward

Aug 31, 2014

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]....

View 1 Replies View Related

C++ :: Extracting Specific Lines Of Text From A Text File

Aug 2, 2014

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.

View 6 Replies View Related

C :: Array Of Structs (adding / Deleting Elements To A File)

Sep 20, 2013

I want to write a program to record my neighborhoods's name and address by using an array of structs and file.

my array of structs is

Code:
#define SIZE 30
typedef struct{
char name[30];
char address[100];
}Detail;
Detail neighbor[SIZE];

And I want to make adding,deleting, and searching functions.Something like

Code:

void add();//Add name and address to a file,
//and add more to the same file if I want to.
void del();//Delete or Change some neighbor's name or address
//in the same file(Can I?)
void search();//Search name and show detail

So I started to code adding function first, but I don't know that I need to use pointer to code each functions relations, and I don't know how to check that my input's already exists yet. But I started some code below...

Code:
void add() {
int i=0;
FILE *fp = fopen("neighborhood.txt", "at");
if ( fp != NULL ) {
do{

[Code]......

View 8 Replies View Related

C :: How To Find Number Of Elements In Single Line Of Dat File

Oct 30, 2013

How would i get the total amount of elements From the input file(The .dat file) and then store them in a variable?Here is an example to show you what i want. If a line on the .dat file looked like this

1 2 3 4 5 6 7

How would i find the total number of elements? For example the total number of elements in this line would be 7.

View 9 Replies View Related

C++ :: How To Read Multiple Elements In File To Parallel Arrays

Apr 19, 2013

I have a txt file that looks like this:

Student ID:97707; Grades: 87.73, 90.41, 91.74, 95.04, 99.13; Name:Davis, Artur
Student ID:23628; Grades: 58.09, 65.18, 68.62, 68.62, 98.05; Name:Davis, Susan
Student ID:49024; Grades: 18.37, 66.06, 68.07, 80.91, 96.47; Name:DeGette, Diana

-I need to read the id, grades and names;
-The id to a separate array
-The grades to a 2-d array
-And the names to a c style string.

Where do I start, im having trouble read the dummy to start

int main() {
char filename[15] = "ex.txt";
string names[MAX_NAMES];
double grades[MAX_ROWS][MAX_COLS];
int id[MAX_IDS];
int index = 0;
ifstream fin;

[Code] .....

View 3 Replies View Related

C++ :: Data File Handling Error - Character Strings Not Copied On Text File

Nov 24, 2013

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?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved