Sender: tim AT picard DOT skynet DOT be Message-ID: <3B25BF27.CC6B5402@falconsoft.be> Date: Tue, 12 Jun 2001 09:05:11 +0200 From: Tim Van Holder Organization: Anubex N.V. X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.16-3 i686) X-Accept-Language: en, nl-BE, nl MIME-Version: 1.0 To: Dr Joolz , djgpp AT delorie DOT com Subject: Re: How to clear char array buffer[]? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com > 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... You never show the declaration of your buffer, but I assume it'll be something like char buffer[MAX]; If this is the case, simply use memset() to clear the buffer; simply adding memset (buffer, 0, sizeof buffer); at the end of your outer while loop should do it. IIRC, the >> operator skips whitespace by default; since in your example you're tokenizing using whitespace, you could simply use something like ifstream fin(blah); string token; while (!fin.eof ()) { fin >> token; // blah } -- Tim Van Holder - Anubex N.V. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= This message was posted using plain text. I do not endorse any products or services that may be hyperlinked to this message.