File reading problem probably newline character

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • utab

    #1

    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(contr ol_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(linei n,"$ Nodes of the Entire Model") == 0){
    while((control_ char=inoutFile. get()) != '$'){ // read until
    the other block

    inoutFile.ignor e(std::numeric_ limits<std::str eamsize>::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.

  • TB

    #2
    Re: File reading problem probably newline character

    utab skrev:[color=blue]
    > 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(contr ol_char in the code) on the
    > newline results in (-1 and y with two dots on top of y) I could not[/color]

    ΓΏ

    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

    Comment

    Working...