C++ :: Reading From TXT File / Replacing Word And Then Overwriting

Nov 21, 2014

My goal is to open a .txt file and replace words in it then overwrite it. My goal is half way done. It couts it perfectly, but I am having a hard time overwriting the whole text file exactly how it couts it. I want the text to be exactly how it is displayed. In this example, I want to replace "ABC" with "DEF".

Text file "A.txt":
1 2 ABC 4 5
6 ABC 8

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main() {
string Y;
fstream IN("A.txt", ios::in | ios::out);

[Code] ......

View 3 Replies


ADVERTISEMENT

C/C++ :: Reading A File And Replacing Characters With Corresponding String

Mar 27, 2014

So I am supposed to create a program that reads a file and replaces "<" with "<" , ">" with ">" , "&" with "&" , and " " " with """.........

The program takes a file "test.txt" and reads it, replaces the characters above with the corresponding strings, and then writes the output to "scrubbed.txt".

A sample input would be: <something>

and the output would be: <something>

for some reason I am getting garbage In my new file. What am I doing wrong with the code?

#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(int argc, char **argv){
char *inFileName = NULL;
char *outFileName = NULL;
FILE *instream = fopen("test.txt", "r");
FILE *outstream = fopen("scrubbed.txt", "w");

[Code] ....

View 5 Replies View Related

C/C++ :: Replacing Letters In A Word?

Aug 13, 2014

i'm trying to replace letters in a word...here's the code so far

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main (){
string s;

[Code] ...

The problem is if i type "nm" i'm not getting "mn" as the output, it's "mm"

I'm not trying to swap letters between them

View 1 Replies View Related

C++ :: Replacing Word In Char Array

Jul 29, 2014

I'm writing a function that accepts a char array containing the title of a book as parameter, the following then has to take place:

1.) Extra white spaces between words need to be removed [DONE]

2.) Text has to be converted to title case, i.e each new word has to start with a capital letter [DONE]

3.) Lastly I have I text file (minors.txt) containing a number of words that should not be capitalized by the function, like "a" and "an", however I don't know how to implement this.

Example of end product:

ENTER THE TITLE OF THE BOOK: a brief hisTOry OF everyTHING

Correct Output:

bool Book :: convertToTitleCase(char* inTitle) {
int length = strlen(inTitle);
bool thisWordCapped = false;
//Convert paramater to lower case and
//Remove multiple white spaces
for (int x = 0; x < length; x++)

[Code]...

I was thinking of maby reading the words in the text file into a string array, and then comparing the two arrays to ensure that when a word is present in a text file, the word is not capitalized, however I don't know if that is possible between a string array and a char array.

View 3 Replies View Related

C :: Create Word Search By Reading In Characters From A File Into Array

Sep 30, 2013

So the plan is to create a word search by reading in characters from a file into an array. This is my code so far, nowhere near finished but have encountered a problem already:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 20
#define COLUMNS 20
int main()
{

[Code]...

My question is to do with the section highlighted in red... I can't really see why it is not printing out my array (wordsearch), it's probably very basic but I have no C experience so am not too confident in what I'm doing.

View 1 Replies View Related

C++ :: Fstream Class Not Reading Word For Word

Aug 6, 2013

int countTextWords(ifstream * file)
{
string textWord;
int wordCount = 0;
while((*file) >> textWord)
{
wordCount++;
}
return wordCount;
}

for some reason, (*file) >> textWord will not read words into the string. What am I doing wrong?

View 9 Replies View Related

C# :: StreamReader And StreamWriter - Overwriting Specific Line In A File?

Apr 10, 2014

I am currently working on a small project, which is an ATM simulator but, lately, I've been stuck in a part where I have to overwrite a specific line in a .dat file to update the account's checking and savings balance, once the transaction has been done. I have to use StreamReader and StreamWriter to complete the task and I have also being told to try Collections... which I'm not sure as to why.

Here's my code so far:

private void btnOKd_Click(object sender, EventArgs e) {
int transaction = 0;
atmTIMER.Elapsed += new ElapsedEventHandler(timerRESTART);
FileStream fileTRANSACTIONS = new FileStream("C:\Users\Voyage\Desktop\ATMSim\ATMsim\Transactions.dat", FileMode.Open);

[Code] .....

View 14 Replies View Related

C# :: Writing To A File (Not Replacing)

Dec 11, 2011

I have a question about an issue I am having on my final project. Within my ItemEntry.cs form, I am trying to get the application to append the already existing .txt file, rather than prompt the user to replace it. I can't seem to get the StreamWriter and FileStream to allow the user to write to the file.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;

[Code] .....

View 1 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: How To Forbid File Replacing In Fstream Library

Jul 25, 2013

How to forbid file replacing in fstream library for C++?

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile;

[Code] ....

View 5 Replies View Related

C++ :: Word By Word From A Line In File?

Aug 14, 2014

ow to read word by word from a line in file into struct. Say for example:

12345 Joe Lim KH879.00
12233 Kay Suet Yee35.98

to

struct master {
unsigned short int IDnum;
char name[30];
float salesCustomer;
};

View 1 Replies View Related

C/C++ :: Bus Error 10 - Overwriting String Literals

Mar 28, 2014

So I am trying to take a string and replace a certain character with another in the string. The function doesn't return anything, but rather changes the string itself. Why would I be getting a bus error 10?

void replaceChar(char *src, char oldChar, char newChar){
//get length of source string.
int length = 0;
length = (int) strlen(src);
char *newSrc = (char *)malloc((length + 1) * sizeof(char));

[Code] ....

I feel like maybe I can't overwrite existing characters in a string, but I don't know how else to implement this without returning anything, which I am not allowed to do.

View 1 Replies View Related

C++ :: Creating Poem - Cout Overwriting Data

Mar 20, 2012

So in a nutshell I have to write a program that grabs a random line from a file and exchange the numbers for words from other files to create a poem. The problem I have is that when I go to output the parts of the ntca it gets all jumbled and writes over each other. (See output below)

I saw something about a memory leak, but I couldn't see how that could be happening in this program. It's a basic intro level program for a class and I'm just a little stuck.

Code:

void create_poem(const int poem_lines) // called from main function {
//Peform each for each line
for(int x = 1; x <= poem_lines; x++) {
char begin_line[1000];

[Code] ....

Everything works perfectly except for the output which looks like this :

Code:
A 2 2 1 and 1 3 1 // <-- this is the line before translation
junkcarrnet

As stated, I know everything else works through debugging purposes. Just the overwriting is my only problem.

View 1 Replies View Related

C :: Display Function Displays All Letters Of Word Entered Instead Of Word Itself

Feb 18, 2013

I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.

Code:

//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;

[code]....

View 1 Replies View Related

C++ :: Program That Reads A Word From User And Then Print (cout) This Word

Oct 24, 2013

I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:

Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().

View 7 Replies View Related

C/C++ :: Opening Word Document In Turbo Or Any Program In Word Format

Mar 20, 2013

I have a problem to open word document into turbo c++. i don't know how to open if the documents are in word format.

View 1 Replies View Related

C/C++ :: Convert 1st Letter Of Each Word To Uppercase And Then Display Only The Last Word?

Dec 27, 2013

I want a program to display as follows..

if i enter mohandas karamchand gandhi i want output as M K Gandhi.....

i want the c++ code for this program..my error is i am not able to erase the letters of first 2 words..ie my output is Mohandas Karamchand Gandhi..

View 2 Replies View Related

C++ :: Simple Word Counter - Show Repetition Of Word

Apr 25, 2012

I've taken part the text into 1 word per line, but I can't figure out how to printf every word only once and then add (%d) in the end to show how many repetitions of that word there are.

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(){
char *oneword;

[Code] ....

View 3 Replies View Related

C++ :: Replacing Strings In A Vector

May 22, 2014

Alright I hav a program that readings from a txt file but is there a way to replace some of the words that get loaded into the vector so for example if the txt has a list of animals and i want to replace the word bird for book is their a way to do that

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

[Code]....

View 1 Replies View Related

C++ :: Replacing Macro With Constant

Apr 4, 2013

I heard that const shall be preferred over #define . So I start to change my program accordingly.

But then below error message occurs during compilation:

#include "common.h"
#include "definition.h"
#include "particle.h"
int main() {
Particle *p = new Particle();

[Code] .....

I guess the error occurs because, when the line 9 of particle.h (File 4) is compiled, value of const int dimension is not seen by the compiler.

View 6 Replies View Related

C :: How To Find Word And Insert Another Word After That In Text

Dec 20, 2013

I have text (string) and I want to find a given word (it's ok!) and then insert another given word after the first word. The original string is beeing copied into a new string. But something is going wrong!!! Where is my mistake?

(I have some patches...)

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//insert "new_word" after each occurence of "word"
int main(){
char A[100]="In the sentence words the and the.";

[Code]...

View 8 Replies View Related

C++ :: How To Read A Specific Word From A File

Aug 12, 2014

How would one go about doing this? I am very fond with Windows I/O, but not so much with this subject. I am decent with fstream, probably not as skilled at it as I should be, but I assume <fstream> would be a better choice, since it isn't locked to Windows.

Anyway, say I have a .txt file like this:

Bill is a cow.
Bill likes meat.
Bob is a pig.
Bob and Bill are friends.

And I want to count the number of times "Bill" is written. How would I do that?

View 5 Replies View Related

C++ ::  Printing From File One Word At A Time

Jun 27, 2013

I have done an exercise from "Thinking in C++" to print text from a file to the console one line at a time, with the user pressing enter to get the next line.

My original code is below, how could I change it for one word at a time?

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

[Code] .....

I tried to alter my program to print one word at a time by changing "getline(in, word)" to "in >> word", but it prints each new word on a new line, the only input I have found to make the next word appear is Enter, I assume that's why.

Is there a way to make it print one word at a time when the user says, but on the same line?

View 4 Replies View Related

C++ :: How To Jumble A Word Coming From A File

Sep 23, 2013

HOW TO JUMBLE A WORD COMING FROM A FILE?

FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!

[Code] .....

then what's next?

View 13 Replies View Related

C++ :: How To Shuffle A Word Coming From A File

Sep 24, 2013

HOW TO SHUFFLE A WORD COMING FROM A FILE?

FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!

[Code] .....

View 4 Replies View Related

C++ :: Remove Word From A Text File?

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







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