471,585 Members | 1,157 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,585 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 2830
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Kevin T. Ryan | last post: by
22 posts views Thread by Ling Lee | last post: by
7 posts views Thread by Webster | last post: by
20 posts views Thread by sahukar praveen | last post: by
28 posts views Thread by Colin JN Breame | last post: by
8 posts views Thread by siliconwafer | last post: by
40 posts views Thread by googler | last post: by
20 posts views Thread by plmanikandan | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.