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)
|