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.
The goal is to merge two files of names, sort them and remove duplicates.I've managed to merge the two files into a single char array and sort them with a function so they are alphabetical.I'm having problems removing the duplicate entries from the array. Here is my code:
int index = -1; string NewStr = null; char[] lower = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char[] upper = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; foreach (char c in str)
[Code]....
The code above loops through a string and for each character checks to see if it is a lower case character, then checks to see if it an upper case. It then removes it if it is. Leaving only the numbers.
However, it reuses the same string the entire time, never updating the string so it always finds the same (first) character.
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
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.
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
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;
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) {
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.
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...
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.
I am creating small application using c#.net.I removed all image tag using regular expression no I want to remove all video file and flash file also in source code of webpage.
so far I have tried this ...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
I have written this code to remove the comments from an input file and then put it into an output file. The program compiles and runs but it removes the whole line of code when it encounters a /* */ type comment. I believe the problem is in the while loop but I just don't know where.
#include <iostream> #include <fstream> #include <string> using namespace std; int main(void) { string infile, outfile; ifstream source; ofstream target;
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
I have a C++ program that performs calculations on numbers in a text file. However, suppose we have additional words in the text file such as "Title". In this instance, the program will not calculate the numbers in the file because of the text.
How do we remove text from a file using the C++ program? e.g. if I wanted to specify the program to remove any instances of the word "Title", how would I do it?
I am working on a program where I am reading in a text file to be parsed to load data objects into their appropriate classes. I have a class to load in this file and to parse its contents. I am at the point where I would like to include the ability to have both C and C++ style comments in this text file. My current class has a constructor that takes in const std::string for its file name. Upon construction I have a while loop that calls a member function getNextLine() as long as this is true this loader class object then calls parseGui(). All of this works correctly so far. Within the function getNextLine() looks like this:
// ---------------------------------------------------------------------------- // getNextLine() // Returns True If It Got A Line Of Text (Could Be Blank If It Is All Commented Out Or // If It Truly Was A Blank Line). False Is Returned When There Is No More Data In The File bool GuiLoader::getNextLine() { if ( !_file.readLine( _strLine ) ) { return false;
[Code] ....
As you can see this getNextLine() method reads in a single line of text and saves it into its member variable which is a std::string. It increments the line number, then a utility function trims out leading and ending white spaces. The next part is where this class calls a member function to remove comments. It is in here where I need to parse the string to look for comments either "//" C++ style line comments or "/* ... */" C style block comments that can span multiple lines. I have tried many different ways to go about doing this, and I am stuck on the C style comments. A note to consider is this: the way this code is designed is reading in a line of text from the file into a string variable and in doing so it is not logical for me to read in the complete file and do a pre-parse scan or analyzer.
This is what I have so far, however there are still cases that this code will fail on
An example of where this code will fail is when it encounters a single '/' any where on a line of text as it goes into an infinite loop. I am not sure on how to go about skipping this lonely '/' and advanced the index to look for a possible next '/' that belongs to a '//' or a '/*'. I know that this is sort of trivial, but for some reason or another I am having writers block.