|
-
Jul 3rd, 2001, 12:46 PM
#1
General strategy tips needed...
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?
-
Jul 3rd, 2001, 01:18 PM
#2
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).
-
Jul 3rd, 2001, 01:24 PM
#3
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?
-
Jul 3rd, 2001, 02:06 PM
#4
Monday Morning Lunatic
_stat is good to look for. Do a search for stat.c in the C++ forum and there's some code there.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 3rd, 2001, 02:55 PM
#5
Code:
#include <fcntl.h>
#include <io.h>
file = open("C:\\MyFile", O_RDONLY);
long len = filelength(file);
close(file);
-
Jul 3rd, 2001, 03:39 PM
#6
That's not gonna work 'cause you have to declare file(which needs to be an int, btw).
-
Jul 3rd, 2001, 03:45 PM
#7
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|