TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALEX WALKER
from: ANTHONY TIBBS
date: 1997-11-27 20:24:00
subject: How to find current dir?

AW>      How do you test for what the current directory the user
AW> is using?      In a little program I'm writing I'd like
AW> write program output to       a file in the current dir,
AW> what ever that might be.  BTW I'm using      BC++ 3.1.  (But
AW> if the solution only works with later compilers I'd     
AW> still like to know what it is.)
Actually, in the above case . . .
/*
** Example program for writing to "OUTPUT.FIL" in the current
** directory.
**
** This isn't really true C++, but I'm not that familur with the
** ofstream class yet, so . . .
**
** Released Nov '97 by Anthony Tibbs to the public domain.
** UNTESTED.
*/
#include 
#include 
int main (int wArgCount, char **pszArgData)
{
FILE *hOutFile;
char  szTemp [60];
   /*
   ** This is the line that will be written to OUTPUT.FIL
   */
   strcpy (szTemp, "This is a test.\n\n");
   /*
   ** Open OUTPUT.FIL in write mode.
   */
   hOutFile = fopen ("Output.Fil", "wb");
   if (!hOutFile)                               // Error?
   {
      printf ("Error opening \"OUTPUT.FIL\" for write!\n");
      return 1;
   }
   /*
   ** Write the line to the file.
   */
   fputs (szTemp, hOutFile);
   /*
   ** Close the file.
   */
   fclose (hOutFile);
   printf ("File written successfully.\n");
   return 0;
}
Take care,
Anthony
--- timEd/B8
---------------
* Origin: The Tibbs' Point - Ottawa, ON - Private (1:163/215.38)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.