X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Mr. Veli Suorsa" Newsgroups: comp.lang.c,comp.os.msdos.djgpp,comp.lang.c++ Subject: String substitution to another Date: Mon, 03 Dec 2001 13:20:35 -0800 Organization: Oulu Lines: 81 Message-ID: <3C0BEC9D.4D74A6CA@surfeu.fi> NNTP-Posting-Host: otogate2.otol.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: pan.oamk.fi 1007378504 9749 193.167.101.89 (3 Dec 2001 11:21:44 GMT) X-Complaints-To: usenet AT pan DOT oamk DOT fi NNTP-Posting-Date: Mon, 3 Dec 2001 11:21:44 +0000 (UTC) X-Mailer: Mozilla 4.08 [en] (Win16; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi! I need some advices. Please, show me, how I can read text file and substitute one string to another (e.g. 'christmas card' -> 'money') and save file again to same name. Here is an example C program to read text file lines, but what substitute commands should I add to it? Or are there ready functions in C++, too? --- /* Program read lines from file */ #include #include #include #define MAXLINELEN 110 int main( int argc, char *argv[] ) { char filename[85], strline[MAXLINELEN]; int line = 0; FILE *fileptr; /* Test if given parameter */ if ( argc != 2 ) { printf( "\nGive data file name : " ); gets( filename ); } else { /* Copy parameter to filename */ strcpy( filename, argv[1] ); } /* Test if can read file */ if ( ( fileptr = fopen( filename, "r" ) ) == NULL ) { printf( "\nError: File: %s can't read.\n", filename ); exit(0); } /* List file */ printf( "\nFile: %s list :\n", filename ); /* Read and list, while not end of file */ while ( !feof( fileptr ) ) { fgets( strline, MAXLINELEN, fileptr ); printf( "%s", strline ); /* Line counter */ line++; } /* Close file */ fclose( fileptr ); printf( "\n*** Read: %d rows from file: %s.\n", line, filename ); return 0; } --- Thanks in advance! Veli Suorsa --- "People must believe to the future to be able to live!" ********************************** J.V.Snellman, 1890. Oulu, FINLAND *** Suorsa Team Homepage *** Join: http://SuorsaTeam.TopCities.Com/ Mailto:VSuorsa AT Surfeu DOT Fi