so its seems basic right? welll its been driving me mad for the last week this is the 7th time i have started back from scratch and each time i just cant get it to wrok right
and when i get to the part where i rewrite the word back into the file how should i do it? im trying the getline method and im not sure how to delete only one line
welll here is what i have to date :P anyone have an example of this that actually works?
Code:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
int main()
{
char FileContents[500]="three blind mice three blind mice", WordToDelete[10]="three", WordToInsert[10]="real";
char StoreFileContents[500]="three blind mice three blind mice";
int length1=strlen(FileContents);
int length2=strlen(WordToDelete);
int length3=strlen(WordToInsert);
int count,count2,count3, tempcount, newfilelength=length1;
cout<<FileContents<<endl;
for(count=0;count<=length1;count++)
{
if(FileContents[count]==WordToDelete[0])
{
for(count2=count;count2<=(count+length2);count2++)
{
if(count2==(count+length2)){
if(length2==length3)
{
for(count3=count;count3<(count+length2);count3++)
{
FileContents[count3]=WordToInsert[count3-count];
}
}
else if(length2<length3)
{
for(count3=count;count3<(count+length3);count3++)
FileContents[count3]=WordToInsert[count3-count];
FileContents[count3++]=' ';//ok
//problems begin:(
tempcount=count3++;//ok
newfilelength=newfilelength+((length3-length2)+1);//ok
for(count3=tempcount;count3<newfilelength;count3++)
FileContents[count3]=StoreFileContents[count3-(length3-length2)];
}
else if(length2>length3)
{
for(count3=count;count3<(count+length3);count3++)
FileContents[count3]=WordToInsert[count3-count];
tempcount=count3;
newfilelength=newfilelength+((length3-length2)+1);
for(count3=count;count3<newfilelength;count3++)
FileContents[count3]=StoreFileContents[count3-(length3-length2)];
}
}
}
}
}
cout<<endl;
cout<<newfilelength<<" "<<length1<<" "<<count3<<endl;
for(count=0;count<=newfilelength;count++)
cout<<FileContents[count];
cout<<endl;
return (0);
}