bc 2.0 different folder file opening

This is a discussion on bc 2.0 different folder file opening within the C Programming forums, part of the General Programming Boards category; my program ask me to open a file found in a folder which is in the same folder with the ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    20

    Cool bc 2.0 different folder file opening

    my program ask me to open a file found in a folder which is in the same folder with the exe file,without entering the complete path(only the file name).how can i do if i have the following dir.h file(DOS environment ,BC 2.0):

    #if __STDC__
    #define _Cdecl
    #else
    #define _Cdecl cdecl
    #endif

    #if !defined(__DIR_DEF_)
    #define __DIR_DEF_

    struct ffblk {
    char ff_reserved[21];
    char ff_attrib;
    unsigned ff_ftime;
    unsigned ff_fdate;
    long ff_fsize;
    char ff_name[13];
    };

    #define WILDCARDS 0x01
    #define EXTENSION 0x02
    #define FILENAME 0x04
    #define DIRECTORY 0x08
    #define DRIVE 0x10

    #define MAXPATH 80
    #define MAXDRIVE 3
    #define MAXDIR 66
    #define MAXFILE 9
    #define MAXEXT 5

    int _Cdecl chdir (const char *path);
    int _Cdecl findfirst (const char *path, struct ffblk *ffblk,
    int attrib);
    int _Cdecl findnext (struct ffblk *ffblk);
    void _Cdecl fnmerge (char *path,const char *drive,const char *dir,
    const char *name, const char *ext);
    int _Cdecl fnsplit (const char *path, char *drive, char *dir,
    char *name, char *ext);
    int _Cdecl getcurdir (int drive, char *directory);
    char *_Cdecl getcwd (char *buf, int buflen);
    int _Cdecl getdisk (void);
    int _Cdecl mkdir (const char *path);
    char *_Cdecl mktemp (char *template);
    int _Cdecl rmdir (const char *path);
    char *_Cdecl searchpath (const char *file);
    int _Cdecl setdisk (int drive);

    #endif

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    You mean things like

    Code:
    FILE *fp;
    fp = fopen( "file.txt", "r" );   // current dir
    fp = fopen( ".\\file.txt", "r" );   // current dir
    fp = fopen( "c:\\temp\\file.txt", "r" );   // absolute path
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    20

    about.. let me continue

    no, something like:
    cprintf("enter the file to open:")
    gets(filename);
    ?????
    ?
    ?
    fp=fopen(file name,"r")
    where the ?? signes are folder opening(let's say TEMP). TEMP is found in the same place with exe file, but the program knows to open the file(from TEMP folder) if i write only the file name (without complete path) when the program ask me.it opens first the folder.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is this what you get when you try to program for stupid users?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    You lost me.
    If the user types in c:\users\me\folder\file.txt
    then that is the file you will get.

    I suppose you could tokenise the input and generate a series of calls
    Code:
    chdir( "\\" );
    chdir( "users" )
    chdir( "me" );
    chdir( "folder" );
    fopen( "file.txt", "r" );
    But that would just be perverse IMO
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I think they want the user to just type the name of a file. Then, my guess is anyway, the program looks in the current directory. Doesn't find it, opens the first folder. Doesn't find it. Opens the first folder there, doesn't find it... and so on.

    But in the same breath, they use gets, so what can you say...

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    20
    i founded a solution on my other thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21