file validation

Discussion in 'C++' started by ozgun.harmanci, Nov 10, 2007.

  1. Hi everyone,
    I had a big problem with line returns and carriage character
    difference in windows and linux. I think what happened was, the scp
    program i am using in to send file from windows machine to a linux
    machine did not somehow realize that the files i am uploading are
    ascii files and sent them as binary. When I tried to use those files,
    input to another program, in linux I was getting strange problems with
    them until i realized that the line returns and carriages were the
    problem.

    Is there a way in C++ to determine and tell the user that the line
    returns and carriages are compatible with linux or windows to warn
    them against input problems? Specifically i am looking for ansi c
    function to accomplish this in a robust way so as to have the input
    validation correctly set.
    Thanks a lot in advance,
    Oz.
     
    ozgun.harmanci, Nov 10, 2007
    #1
    1. Advertising

  2. ozgun.harmanci wrote:
    > [..]
    > Is there a way in C++ to determine and tell the user that the line
    > returns and carriages are compatible with linux or windows to warn
    > them against input problems? Specifically i am looking for ansi c
    > function to accomplish this in a robust way so as to have the input
    > validation correctly set.


    No. All this you're describing has nothing to do with C++. Besides,
    nobody warns anybody when carriage returns are concerned, but instead
    the code is usually written in such a way that those things do not
    matter, and all files are handled regardless of their originating OS.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 10, 2007
    #2
    1. Advertising

  3. ozgun.harmanci

    David Harmon Guest

    On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
    <> wrote,
    >Is there a way in C++ to determine and tell the user that the line
    >returns and carriages are compatible with linux or windows to warn
    >them against input problems? Specifically i am looking for ansi c


    Open the file with ios::binary. Read it and count the number of LF
    characters that are/are not preceded by CR.
     
    David Harmon, Nov 10, 2007
    #3
  4. * Victor Bazarov:
    > ozgun.harmanci wrote:
    >> [..]
    >> Is there a way in C++ to determine and tell the user that the line
    >> returns and carriages are compatible with linux or windows to warn
    >> them against input problems? Specifically i am looking for ansi c
    >> function to accomplish this in a robust way so as to have the input
    >> validation correctly set.

    >
    > No. All this you're describing has nothing to do with C++. Besides,
    > nobody warns anybody when carriage returns are concerned, but instead
    > the code is usually written in such a way that those things do not
    > matter, and all files are handled regardless of their originating OS.


    I think it is pretty much relevant, a language issue. Because I don't
    think we would have had text mode, I don't think it would be impossible
    to write a standard C++ 'cat' on systems where it's meaningful, if it
    weren't for Windows' line ending convention. And the short of it is
    that for standard input there's no standard system-independent way to
    turn off that infernal havoc-wreaking band aid, but streams that are
    explicitly opened can be opened in binary mode.

    Cheers,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 10, 2007
    #4
  5. ozgun.harmanci

    James Kanze Guest

    On Nov 10, 6:03 pm, "ozgun.harmanci" <> wrote:

    > I had a big problem with line returns and carriage character
    > difference in windows and linux. I think what happened was, the scp
    > program i am using in to send file from windows machine to a linux
    > machine did not somehow realize that the files i am uploading are
    > ascii files and sent them as binary. When I tried to use those files,
    > input to another program, in linux I was getting strange problems with
    > them until i realized that the line returns and carriages were the
    > problem.


    > Is there a way in C++ to determine and tell the user that the line
    > returns and carriages are compatible with linux or windows to warn
    > them against input problems? Specifically i am looking for ansi c
    > function to accomplish this in a robust way so as to have the input
    > validation correctly set.


    When reading a Windows file on Unix, you will usually see an
    additional '\r' in front of every new line. Just ignore it.
    (If you are reading text, it counts as white space---isspace(
    '\r' ) returns true in all the locales I've used---, so in a lot
    of cases, it will be ignored automatically.

    When reading a Unix file under Windows, you formally have an
    illegal text format, which could cause istream to report an
    error. In practice, the implementations I've used all treat an
    LF which is not preceded by a CR as if it were, and read Unix
    files without problems. (This is not the case with some
    programs, however. I don't know what compiler they were
    compiled with.)

    There used to be two programs, unix2dos and dos2unix, under
    Unix, which would convert the files "after the fact", if you
    ended up with the wrong type. I don't seem to have them on my
    Linux here at home, however. Of course, they'd be very easy to
    write, as long as you read and write in binary (so that you
    control the representation of line endings). But that doesn't
    help much in practice, since most of the time, such problems
    occur because of a shared file system.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Nov 11, 2007
    #5
  6. ozgun.harmanci

    BobR Guest

    David Harmon wrote in message...
    > On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
    > <> wrote,
    > >Is there a way in C++ to determine and tell the user that the line
    > >returns and carriages are compatible with linux or windows to warn
    > >them against input problems? Specifically i am looking for ansi c

    >
    > Open the file with ios::binary.


    Or:

    std::ifstream in( "file.typ", std::ios_base::in |
    std::ios_base::binary );

    --
    Bob R
    POVrookie
     
    BobR, Nov 11, 2007
    #6
  7. I agree that this question might not be perfectly relevant with this
    group but my question was: I am looking for an ansi c/c++ way to deal
    with the problem. I think I am going to go with reading file in binary
    and checking for CR LF characters.. thanks a lot everyone..

    On Nov 11, 1:11 pm, "BobR" <> wrote:
    > David Harmon wrote in message...
    > > On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
    > > <> wrote,
    > > >Is there a way in C++ to determine and tell the user that the line
    > > >returns and carriages are compatible with linux or windows to warn
    > > >them against input problems? Specifically i am looking for ansi c

    >
    > > Open the file with ios::binary.

    >
    > Or:
    >
    > std::ifstream in( "file.typ", std::ios_base::in |
    > std::ios_base::binary );
    >
    > --
    > Bob R
    > POVrookie
     
    ozgun.harmanci, Nov 11, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,703
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,524
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,144
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. Lucas Tam
    Replies:
    2
    Views:
    1,127
    Lucas Tam
    Feb 26, 2004
Loading...

Share This Page