i want to overwrite some part of string with other string in a file.
i want to overwrite in each line of file.
i wrote the below code, but this is not working please help.
suppose file has multiple line where one of the line containe:--- abcdefghioverwritefxyz89760
that should convert as below:-- abcdefghichangemadexyz89760
char lineFileRecord [150];
fp = fopen( "abc.txt","r+");
while ( fgets (lineFileRecord , 150 , fp) != NULL )
{
char* sample;
sample = strstr( lineFileRecord, "overwritef");
//overwritef and changemade both have same size
if( sample != NULL )
{
strncpy( sample, "changemade",10 ); // is the the correct way.
}
}
the above code in not replacing the contents. of the file. please correct me if i am wrong any.
thanks for reply.