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
ADVERTISEMENT
May 7, 2013
Is there a way to replace 3 char's in a string. For example i have a string containing
s = "The school is called 7x8"
I want to replace the "7x8" with "LSU". But the "x" can be any letter or number.
Is there a way to do that ?
View 6 Replies
View Related
May 4, 2013
#include <iostream>
using namespace std;
int replace(char *ptr, char c1, char c2);
int replace(char *ptr, char c1, char c2){
int count = 0;
int i = 0;
[Code] ......
Segmentation fault (core dumped)
View 5 Replies
View Related
Aug 9, 2013
I've to do a function that removes char(input by user) from string , only if it appeared and to reduce spaces.
for instance: string = abcabcd ; and the char= c/
the return string is : ababd
void removeChar(char string2[SIZE], char ch) {
//---NOTE--- its not completely works - there is a problem i.
int read = 0, write = 0;
[Code].....
View 6 Replies
View Related
Aug 6, 2013
I need to remove a char from string that found ;
For example : string- abcdfe
the char ch is - c
and the return new string is : abdfe.
I did as follow:
void removeChar(char string2[SIZE], char ch) {
char input= 'a'; // for example replace something
int i=0;
if(string2[i]== ch && string2[i]!='/0') {
string2[i]= input;
}
i++;
}
and in the main : I only called to this function above and print string.
View 4 Replies
View Related
Apr 15, 2014
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:
Code:
#include <stdio.h>
#include <string.h>
#define NUMSTR 10
#define STRLNG 9
[Code]....
View 3 Replies
View Related
Jul 5, 2013
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.
View 6 Replies
View Related
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
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
View Related
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
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
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
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
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
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
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
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
Dec 11, 2012
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;
[Code] .....
View 1 Replies
View Related
Mar 11, 2013
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;
[Code]...
View 3 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
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
Feb 20, 2015
I have tried with some logic for removing comma operator in test.ini file but its not working how to remove comma and get output. For example:
Input
inside test.ini file the name is in format,
ajs,18.0,15.0
expected output
ajs 18.0 15.0
but I am getting,
ats,18.0,25.0 2686760 4200912
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char strConfName[25] ;
float a,b;
[Code] .....
View 1 Replies
View Related
May 24, 2014
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?
View 1 Replies
View Related
Jul 5, 2013
I'd like to remove the character % from a text file using c++
View 8 Replies
View Related
Apr 12, 2014
I'm using the code found on the site here:
//* remove example: remove myfile.txt */
#include <stdio.h>
int main () {
if( remove( "myfile.txt" ) != 0 )
perror( "Error deleting file" );
[Code] ....
I replaced the myfile.txt with the directory of the file I want deleted.
"C:SOUNDSsavegame.dat"
It returns: Error deleting file. No such file or directory exists.
I've triple checked the directory. Its correct. I must be using this incorrectly. How?
View 5 Replies
View Related
Mar 12, 2015
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
// ----------------------------------------------------------------------------
// removeComments()
void GuiLoader::removeComments() {
const unsigned tokenLength = 1;
static std::string::size_type indexA;
static std::string::size_type indexB;
const std::string commentStartingToken( "/" );
const std::string blockCommentStartingQualifier( "*" );
[Code] .....
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.
View 14 Replies
View Related