PDA

Click to See Complete Forum and Search --> : General strategy tips needed...


wossname
Jul 3rd, 2001, 12:46 PM
Hi,

before I get too far into this - I'M USING THE RHIDE/DJGPP C++ COMPILER FOR DOS

What I need to accomplish:

1. The user supplies a filename (full path)
2. My program reads in datafrom that file in 4 byte chunks into an array where each element contains 16 unsigned long ints. (If the file isn't quite enough to fill the last element in the array then I need to pad the element out with zeros).
3. Apply some logic to all the data (I have this sorted out already)

---------
Things I don't know at runtime:

1. The length of the file, and therefore how many elements I will need in the array.

---------

Things I need to know:

1. The length of the file before I open it

1. It would be nice to have either: a graphical interface for selecting a filename (much like a common dialog box) *OR* some way of validating the format of the file path string.

So is there a library for filename validation or the common dialog idea?

denniswrenn
Jul 3rd, 2001, 01:18 PM
Why do you need to know the length of the file before you open it?
Right now I can't think of a way to do that, but otherwise, you can use _filelength(handle) in io.h (this is used with _open, _read, _write, and _close).

wossname
Jul 3rd, 2001, 01:24 PM
I want to know the length in bytes before I open it because I don't want to change the LastAccessed property of the file.

Unless opening it using fin() doesn't effect this property, does it? :confused:

parksie
Jul 3rd, 2001, 02:06 PM
_stat is good to look for. Do a search for stat.c in the C++ forum and there's some code there.

Megatron
Jul 3rd, 2001, 02:55 PM
#include <fcntl.h>
#include <io.h>

file = open("C:\\MyFile", O_RDONLY);
long len = filelength(file);
close(file);

denniswrenn
Jul 3rd, 2001, 03:39 PM
That's not gonna work 'cause you have to declare file(which needs to be an int, btw).

parksie
Jul 3rd, 2001, 03:45 PM
It would never work because it's not in a function block - anyway it was a code snippet, not designed to work ;)

You don't need the return type because the function documentation will tell you.