473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

file validation

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.

Nov 10 '07 #1
5 2330
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
Nov 10 '07 #2
On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
<oz************@gmail.comwrote,
>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.
Nov 10 '07 #3
On Nov 10, 6:03 pm, "ozgun.harmanci" <ozgun.harma...@gmail.comwrote:
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:ja*********@gmail.com
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

Nov 11 '07 #4

David Harmon wrote in message...
On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
<oz************@gmail.comwrote,
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
Nov 11 '07 #5
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" <removeBadB...@worldnet.att.netwrote:
David Harmon wrote in message...
On Sat, 10 Nov 2007 17:03:05 -0000 in comp.lang.c++, "ozgun.harmanci"
<ozgun.harma...@gmail.comwrote,
>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

Nov 11 '07 #6

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

Similar topics

3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
6
by: Nad | last post by:
Hello, I need some help with this: I am trying to update some data using XmlTextWriter. I instantiate first and then do some validation and then copy data into the dataset. Finally I commit...
3
by: Me | last post by:
Hi all What is the best way to upload and then process a csv file that contains around 20,000 records? The data needs to be validated and then added to the database. All records that dont...
0
by: info | last post by:
Hi, Is it possible to include in the Schema validation file, every custom error message for each validation rules? This mean, in the same xsd file we can have the validation rules (patterns)...
0
by: Webmills | last post by:
Hi I have a form containing a File Upload Control, Required Field Validator (connected to the file upload control) RegularExpressionValidator (connected to the file upload control,...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
21
by: Jack White | last post by:
Hi there, I've created a strongly-typed "DataSet" using VS. If I save the data via "DataSet.WriteXml()" and later prompt my users for the name of the file in order to read it back in again...
6
by: Mohammad Omer | last post by:
Hi, I tried to validate file path without calling file creating functions. Is it possible? How? Regards, -aims
9
hsriat
by: hsriat | last post by:
How can I add my validation script to this file upload code? Validation Script:function validate(frm) { if (!/(\.(gif|jpg|jpeg|png))$/i.test(frm.file.value)){ alert('Invalid file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.