![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
c++ reading from a file ...
so i am reading from a file character by character, coz i have to ...
i am taking care of the eof thing as follows... if (c == -1) {tell the program to stop reading from the file} now how do i tackle newline? if (c == 10) { do what?} how do i tell program to start reading from the next line? also 10 is the ascii code for '/n' .. right? (i'm using windows) |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
In the first place, 'c' won't necessarily equal -1 when you hit EOF unless you are reading a file written in Window's text mode, but reading it in binary mode. EOF is a condition, not content, except as mentioned above. Some read mechanisms will stash the condition in there, however. You don't happen to mention the type of input function you are using, which would seem to be a necessary requisite in the minds of anyone with 37 posts. Woops, just noticed, you haven't reached 37....
0x10 is the ASCII code for newline, alright, but you might get 0x13 for carriage return/enter, depending upon how the file was written. Dare I suggest that you produce (for our inspection) some actual code, what you expect of it, how, precisely, it is failing to meet your expectations, and some actual error/warning messages, if any. Time to get on the stick and quit expecting mind-reading, Mr. Noob.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
just a few questions:
is the variable "c" the character you are reading from file?? if yes.. are you using .get(c) to fetch each character from the file..? do you want to read a new line when the file pointer still has not finished reading the line itself..? |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
where fin is the ifstream variable ... when i read a text file ... if it encounters end of line .. i want it to "skip" or should i say ignore? that character and move on to the next line ... so ... text: blah yes it would read 'h' and then it will read /n and then it will be move on to reading b... i hope i am making sense? Last edited by programmingnoob; Apr 22nd, 2006 at 6:43 PM. |
|
|
|
|
|
|
#5 | ||
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Quote:
Quote:
Have you looked into the getline() function at all? assuming you're wanting to read a whole line/word/delimted amount. And your code would be easier to read (IMHO) if you compared the values to the characters rather than the ASCII values (i.e. 'h' and '\n'). |
||
|
|
|
|
|
#6 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
and i cant use getline() function because i need to read charcater by character |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|