Newsgroups: comp.os.msdos.djgpp,gnu.g++.help Subject: Re: How to clear char array buffer[]? References: From: Gerall Kahla Message-ID: <871yoplvje.fsf@coin.chromebob.com> Lines: 46 User-Agent: Gnus/5.090001 (Oort Gnus v0.01) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: 12 Jun 2001 07:41:57 -0500 NNTP-Posting-Host: 208.191.93.169 X-Complaints-To: abuse AT swbell DOT net X-Trace: nnrp1.sbc.net 992349596 208.191.93.169 (Tue, 12 Jun 2001 07:39:56 CDT) NNTP-Posting-Date: Tue, 12 Jun 2001 07:39:56 CDT Organization: SBC Internet Services To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Dr Joolz" writes: > Dear all, I have some code like this: > > while (!fin.eof()) { > fin.getline(buffer, MAX); > token = strtok( buffer, seps ); > while ( token != NULL ) { > dict.insertN(token, i); > cout << i << token << endl; > cout << dict; > token = strtok( NULL, seps ); > i++; > } > } > > and it is causing problems with what's read in buffer every time getline is > executed, if I used a different char buffer in getline in each while exec > problem gone. So I know it is buffer that's not being reset to empty at the > end of each while loop, how do I do that? I tried buffer = ""; or NULL or > assigning buffer[i] = '\0' etc won't work... > How about adding a line like this: > while (!fin.eof()) { // this clears the buffer before reading memset( buffer, '\0', sizeof(buffer)); > fin.getline(buffer, MAX); > token = strtok( buffer, seps ); > while ( token != NULL ) { > dict.insertN(token, i); > cout << i << token << endl; > cout << dict; > token = strtok( NULL, seps ); > i++; > } > } -- Gerall Kahla a.k.a the Celestial Mechanic http://chromebob.com -- homepage http://chromebob.com/public-key.asc -- GnuPG public key