-
April 16th, 2011, 01:24 PM
#1
Code Help!
My program is supposed to read in a file and a word from the user then replace every instance of the word inside the program with another word entered in by the user. I keep getting function errors and cant get past the compiling process
Here is my code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
//Varibles needed to make sure that the program will run effectively
fstream dataFile;
char *buffer;
string find, change;
int count = 0;
int length;
//Opening the data file to be a input and output (Read and Write)
dataFile.open("input.txt", ios::in|ios:ut);
//Testing to make the file opened
if (!dataFile)
{
cout << "File open error!" << endl;
return 0;
}
//Getting the length of the file
dataFile.seekg (0, ios::end);
length = dataFile.tellg();
dataFile.seekg (0, ios::beg);
//allocating memory for the file
buffer = new char [length];
//Read the buffer into the file
dataFile.get(*buffer);
//Asking the user what word would they like to search for
cout << "What word do you want to search for?" << endl;
cin >> find;
//Asking the user what word they want to use to replace
cout << "What word do you want to replace the first word with?" << endl;
cin >> change;
while (!dataFile.eof())
{
do {
if (strstr(find,*buffer) == 0)
{
count++;
}
} while (!dataFile.eof());
dataFile.replace (buffer, find, change);
}
cout << buffer;
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|