472,958 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

File reading problem probably newline character

Hi there I am trying to read from a file,
I am trying to read certain fields,there are 6 fields in this file like

--------/--------/--------/--------/--------/--------/

All fields are 8 characters width and I am comparing the first
character of the line with the $ sign which seperates different blocks
of information

$ Nodes of the Entire Model
GRID 1 .25 .25 0.
GRID 2 .2 .25 0.
GRID 3 .15 .25 0.
GRID 4 .1 .25 0.
GRID 5 .05 .25 0.
GRID 6 0. .25 0.
GRID 7 .25 .2 0.
GRID 8 .2 .2 0.
GRID 9 .15 .2 0.
GRID 10 .1 .2 0.
GRID 11 .05 .2 0.
GRID 12 0. .2 0.
GRID 13 .25 .15 0.
GRID 14 .2 .15 0.
GRID 15 .15 .15 0.
GRID 16 .1 .15 0.
GRID 17 .05 .15 0.
GRID 18 0. .15 0.
GRID 19 .25 .1 0.
GRID 20 .2 .1 0.
$ Loads for Load Case : Default

I can read the first line of the input which is GRID 1 .... and
the result is 'G'
after that reading the first charecter(control_char in the code) on the
newline results in (-1 and y with two dots on top of y) I could not
figure out my problem. My code for this part is
..
..
..
while(inoutFile.getline(linein,80,'\n')){
if(strcmp(linein,"$ Nodes of the Entire Model") == 0){
while((control_char=inoutFile.get()) != '$'){ // read until
the other block

inoutFile.ignore(std::numeric_limits<std::streamsi ze>::max(),'\n');
}
}
if(control_char=='$')
break;
}
..
..
..

Can there be a problem related with binary and text files? Because the
file I am trying to read is the output of a package program and I do
not know the newline characters that are used to these files. (I also
tried it with a file that I know the newline character is '\n', the
same problem still persists with the file I created myself as well :-((
)

Any help will be appreciated.

Thanks.

Mar 13 '06 #1
1 2970
TB
utab skrev:
Hi there I am trying to read from a file,
I am trying to read certain fields,there are 6 fields in this file like

--------/--------/--------/--------/--------/--------/

All fields are 8 characters width and I am comparing the first
character of the line with the $ sign which seperates different blocks
of information

$ Nodes of the Entire Model
GRID 1 .25 .25 0.
GRID 2 .2 .25 0.
GRID 3 .15 .25 0.
GRID 4 .1 .25 0.
GRID 5 .05 .25 0.
GRID 6 0. .25 0.
GRID 7 .25 .2 0.
GRID 8 .2 .2 0.
GRID 9 .15 .2 0.
GRID 10 .1 .2 0.
GRID 11 .05 .2 0.
GRID 12 0. .2 0.
GRID 13 .25 .15 0.
GRID 14 .2 .15 0.
GRID 15 .15 .15 0.
GRID 16 .1 .15 0.
GRID 17 .05 .15 0.
GRID 18 0. .15 0.
GRID 19 .25 .1 0.
GRID 20 .2 .1 0.
$ Loads for Load Case : Default

I can read the first line of the input which is GRID 1 .... and
the result is 'G'
after that reading the first charecter(control_char in the code) on the
newline results in (-1 and y with two dots on top of y) I could not




I'd guess you hit the end of the file. You need to check if the stream
is still valid after each extraction.

<snip>

--
TB @ SWEDEN
Mar 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kevin T. Ryan | last post by:
Hi All - I'm not sure, but I'm wondering if this is a bug, or maybe (more likely) I'm misunderstanding something...see below: >>> f = open('testfile', 'w') >>> f.write('kevin\n') >>>...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
7
by: Webster | last post by:
Hello, I have to read a file with a single "command" per line. But how do I read to the end of the line?? I am using C style filepointers (not by choice :( ) Thanks for any help! --...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
28
by: Colin JN Breame | last post by:
Hi, Fairly new to C. What is the best way to read a line (\n terminated) from a file? Ive looked at fscanf but was not sure which format specifier to use. (%s perhaps). Thanks Colin
8
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
20
by: plmanikandan | last post by:
Hi, I need to read a file line by line.each line contains different number of characters.I opened file using fopen function.is there any function to read the file line by line Regards, Mani
9
by: sherifffruitfly | last post by:
Hi, I've a got a little (exercise) program that reads data from a file and puts it into struct members. I run into trouble when one of the data pieces is comprised of several words (eg "john...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.