Server : Apache System : Linux profile 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 User : apache ( 48) PHP Version : 8.0.28 Disable Function : NONE Directory : /var/www/html/mmishra/nweb/ |
#include <stdio.h>
#include <string.h>
int main ( ) {
char buff[BUFSIZ]; // the input line
char newbuff[BUFSIZ]; // the results of any editing
char findme[] = "hello";
char replacewith[] = "world";
FILE *in, *out;
in = fopen( "file.txt", "r" );
out= fopen( "new.txt", "w" );
while ( fgets( buff, BUFSIZ, in ) != NULL ) {
if ( strstr( buff, findme ) != NULL ) {
// do 1 or more replacements
// the result should be placed in newbuff
// just watch you dont overflow newbuff...
} else {
// nothing to do - the input line is the output line
strcpy( newbuff, buff );
}
fputs( newbuff, out );
}
fclose( in );
fclose( out );
return 0;
}