My program has a function that reads in information until it hits a designated character, takes the text just before that character, does something with it, and then comes back for more text starting at that designated character.

So...
Special character is: 'z'
Text file: "This is a lot of text and I am only saying zune because it possess the character."

The first chunk : "This is a lot of text and I am only saying "
The second chunk: "zune because it possess the character."

My dilemma is that in order to check ahead and see the 'z', I need to first read in the z and then check its ascii number. This causes problems because the file pointer loses the 'z' and now is "une because it possess the character."

Is there any way to check ahead without losing information while reading? I'm looking for maybe a function call I overlooked or a method to do so. You do not need to present code.

Thanks

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

You'd be better off reading the entire line and looking through the array rather than trying to mess around with complex file reading techniques. If you can read the entire file, so much the better.

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

hmm..
well not diving into my project too much, I need to tell whether something is "folded" which mean I need to find in sequential order'\r''\n' and a ' ' on the next line. If the space is anything other than a space it is declared not folded and will be read later. The problem occurs when there it is not folded and the program actually takes in the first character of the next string to test for the line being folded.

I just was reading my book and came across ungetc(); might be useful.

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

success!
ungetc() is a lifesaver. Thanks for commenting anyways. Always helpful!

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

But ungetc() is non-standard and therefore not recommended. It will not work in most compilers.

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

Thanks for the heads up I'll ask my TA if its okay to use.

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

But ungetc() is non-standard and therefore not recommended. It will not work in most compilers.

Standard section 7.19.7.11 (The ungetc function) begs to differ.

Re: Read A Character In Text File Pointer WITHOUT losing information 80 80

Standard section 7.19.7.11 (The ungetc function) begs to differ.

Ahh, sorry. I forgot it's not related to getch() . My mistake.

But I still think it shouldn't be used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.