Results 1 to 7 of 7

Thread: General strategy tips needed...

  1. #1
    wossname
    Guest

    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?

  2. #2
    denniswrenn
    Guest
    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).

  3. #3
    wossname
    Guest
    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?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    _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

  5. #5
    Megatron
    Guest
    Code:
    #include <fcntl.h>
    #include <io.h>
    
    file = open("C:\\MyFile", O_RDONLY);
    long len = filelength(file);
    close(file);

  6. #6
    denniswrenn
    Guest
    That's not gonna work 'cause you have to declare file(which needs to be an int, btw).

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width