anyone have any other suggestion? here is what i have now....
this is way harder than i tought it would be
Code:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
int main()
{
char filename[20], wordtofind[20], wordtoreplace[20], input[200];
int length=0,length2=0,length3=0, count=0, count2=0,count3=0,count4=0, temp;
cout<<"Enter the name of file: ";
cin>>filename;
cin.ignore(20,'\n');
cout<<"Enter word to search for: ";
cin.getline(wordtofind,20);
cout<<"Enter word to replace it with: ";
cin.getline(wordtoreplace,20);
length=strlen(wordtofind);
fstream file;
file.open(filename,ios::nocreate|ios::in|ios::out);
if(file.fail()){
cout<<"File could not be openend"<<endl;
return (0);
}
else{
while(file.getline(input,200,'\n'))
{
length2=strlen(input);
length3=strlen(wordtoreplace);
for(count=0;count<length2;count++)
{
if(input[count]==wordtofind[0]){
temp=count;
for(count2=0;count2<=length;count2++)
{
if(input[temp++]!=wordtofind[count2])
break;
if(count2==length){
for(count3=0;count3<count;count3++)
{
file.seekp(count3);
file<<input[count3];
}
for(count4=0;count4<length3;count3++)
{
file.seekp(count3++);
file<<wordtoreplace[count3];
}
for(count3;count3<length2;count3++)
{
file<<input[count3];
}
}
}
}
}
}
}
file.close();
return (0);
}