We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,697 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Read A Character In Text File Pointer WITHOUT losing information

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

4
Contributors
7
Replies
10 Hours
Discussion Span
2 Years Ago
Last Updated
8
Views
Question
Answered
BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36

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.

BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by WaltP

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

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36

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

BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

Trentacle
Junior Poster
107 posts since Dec 2010
Reputation Points: 125
Solved Threads: 25
Skill Endorsements: 0

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.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0875 seconds using 2.71MB