for some reason i just cant seem to be able to see th4e bug that screws up my replacement of words
heres the code
Code:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
int main()
{
char FileContents[500]="three blind mice three blind mice three blind mice", WordToDelete[10]="three", WordToInsert[10]="weirdos";
char StoreFileContents[500]="three blind mice three blind mice three blind mice";
int length1=strlen(FileContents);
int length2=strlen(WordToDelete);
int length3=strlen(WordToInsert);
int count,count2,count3;
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)
{
//count is location of first letter of the word to remove
for(count3=count;count3<=(count+length3);count3++)
FileContents[count3]=WordToInsert[count3-count];
for(count3=count;count3<=length1;count3++)
FileContents[count3+length3+(length3-length2)]=StoreFileContents[count3+length2];
}
}
}
}
cout<<endl;
for(count=0;count<=length1;count++)
cout<<FileContents[count];
cout<<endl;
cout<<FileContents[20];
return (0);
}