I have to validate orders from a flat file (ASCII, fixed length). This file contains different fields: integer, double, float, date, time. What's the best way to check, if all these fields just contain valid data (a valid integer, a valid date, ...)?

Thank's a lot.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'd use a tool suited to the job: Perl.

But if you can't learn a new language, or are tied to C++ for the rest of your system, there are various parsers that can help.  I've not done any myself, but LEXX and YACC are tools that my team have used in the past.  
Is this for a school assignment?

You will have to read each record and test each field "manually"  It is probably best to read the record in as an ASCII string, then examine the seperate fields inside the string.  (Probably best to read the record using the GetLine() function.)  

That's about all anyone can say unless yoiu give us mre details.
Probably no easy way. You'll have to labouriously read each field and check it is valid.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

The way I would do it is spilt the file up with c++ then parse it with  awk. I do this all the time. If you can't do that shoot yourself. You are in for the ultimate in programming bordom.
jaroslavAuthor Commented:
for which type of field shall I use what command to check (e.g. integer = strtol(*a, **b, i)?
Preferable iostreams or sscanf(). Do not use strtol and its companions because it returns a 0 on error. A 0 is usually a valid number.
scanf type specifiers:
integer:      %d
long:            %ld
float:            %f
double:            %lf
long double:      %Lf
char*            %s
Most allow addotional width specification
Check out the manual on scanf, there are so many possiblities. For simple flat files it might even be possible to scan an entire line in one step, for example:
could be used to scan the format
  12 chars
  8 digit number
  25 characters
forgot the arguments:
  char str_field1[13];
  char str_field3[26];
  int  int_field2;
scanf("%12c%8d%25c", str_field1, int_field2, str_field3);
What would you consider to be a valid integer?  What dates would you consider to be invalud?
jaroslavAuthor Commented:
valid integer: just numeric values (0-9), without point

valid date: date in different formats,
but checking for correct day, month and leap year

Answer from KangaRoo sounds good, but does not solve the problem, because scanf from stdin is not the same for me as reading from file.

I read as follows:
ReadFile(hFile, pBuffer, sizeof(pBuffer) -1, &fRead, NULL);
pBuffer[fRead] = '\0';
if (fRead == 0)
} while (fRead > 0);

So I have pBuffer to check.
use sscanf() for that.
There are some variations on scanf():

fscanf      scans and formats input from a stream
scanf      scans and formats input from stdin
sscanf      scans and formats input from a string
vfscanf      scans and formats input from a stream, using an argument list
vscanf      scans and formats input from stdin using an argument list
vsscanf      scans and formats input from a string, using an argument list

The best way to go about is probably to use fgets to read a line into a buffer, then parse the string with sscanf()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaroslavAuthor Commented:
Good answer, KangaRoo tried till I understood!
Note that the versions that begin with a "v" are non-standard.  You might not have them on your compiler.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.