Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > file validation

Reply
Thread Tools

file validation

 
 
ozgun.harmanci
Guest
Posts: n/a
 
      11-10-2007
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.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-10-2007
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


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      11-10-2007
On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-10-2007
* 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?
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-11-2007
On Nov 10, 6:03 pm, "ozgun.harmanci" <(E-Mail Removed)> 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:(E-Mail Removed)
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

 
Reply With Quote
 
BobR
Guest
Posts: n/a
 
      11-11-2007

David Harmon wrote in message...
> On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
> <(E-Mail Removed)> 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


 
Reply With Quote
 
ozgun.harmanci
Guest
Posts: n/a
 
      11-11-2007
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" <(E-Mail Removed)> wrote:
> David Harmon wrote in message...
> > On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
> > <(E-Mail Removed)> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a Validation Error in a Validation Summary Control Lucas Tam ASP .Net 2 02-26-2004 07:49 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM
validation summary doesnt display when there's client-side validation Libs ASP .Net 0 06-25-2003 03:05 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments