X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Aaron Isotton" Newsgroups: comp.lang.c,comp.os.msdos.djgpp,comp.lang.c++ Subject: Re: String substitution to another Date: Mon, 3 Dec 2001 14:36:50 +0100 Organization: WIND Telecomunicazioni S.p.A. Lines: 88 Message-ID: <9ufv4j$qho$1@nreadb.inwind.it> References: <3C0BEC9D DOT 4D74A6CA AT surfeu DOT fi> NNTP-Posting-Host: 62.98.241.53 X-Trace: nreadb.inwind.it 1007386579 27192 62.98.241.53 (3 Dec 2001 13:36:19 GMT) X-Complaints-To: abuse AT inwind DOT it X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Mr. Veli Suorsa" ha scritto nel messaggio news:3C0BEC9D DOT 4D74A6CA AT surfeu DOT fi... > 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 > > Use the std::string class. - Aaron