![]() |
| | #1 |
| Registered User Join Date: Mar 2005
Posts: 15
| creating a file in the same directory as the executable program Do I create a file with fopen? If not, what function do I use? Also, what directory path do I specify if I want to create the file in the same folder as the .exe file of the program that is creating the file? Thank you. |
| 1978Corvette is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Which OS/Compiler are you using? |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Mar 2005
Posts: 15
| Win XP/ Dev-C++ |
| 1978Corvette is offline | |
| | #4 |
| Been here, done that. Join Date: May 2003
Posts: 1,036
| Yes, fopen() for write will create the file.
__________________ There are only 10 types of people in the world -- those that use binary, and those that don't |
| WaltP is offline | |
| | #5 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| This code should work for you. It will create the file MyFile.ext in the same directory as your executable. Make sure and include <windows.h>. Another option is to use the executable path given to your main() or WinMain() function. Code: char buff[MAX_PATH], *p;
FILE *f;
GetModuleFilePath(NULL,buff,MAX_PATH);
p = strrchr(buff, '\\');
if(p)
{
strcpy(p+1,"MyFile.ext");
}
f = fopen(buff,"w");
|
| bithub is offline | |
| | #6 |
| Registered User Join Date: Feb 2006
Posts: 17
| Just call fopen with the file name and the "w" parameter and it will create/overwrite a file in the executable's directory... |
| tcpl is offline | |
| | #7 | |
| Registered User Join Date: Mar 2005
Posts: 15
| Quote:
| |
| 1978Corvette is offline | |
| | #8 | ||
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Quote:
Quote:
| ||
| bithub is offline | |
| | #9 | |
| Registered User Join Date: Feb 2006
Posts: 17
| Quote:
| |
| tcpl is offline | |
| | #10 |
| Just Lurking Join Date: Oct 2002
Posts: 4,990
| A related thread elseweb from a little while back... http://forums.devshed.com/c-programm...ry-314721.html
__________________ 7. It is easier to write an incorrect program than understand a correct one. 40. There are two ways to write error-free programs; only the third one works.* |
| Dave_Sinkula is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ std routines | siavoshkc | C++ Programming | 33 | 07-28-2006 12:13 AM |
| Batch file programming | year2038bug | Tech Board | 10 | 09-05-2005 03:30 PM |
| Creating a file in a certain directory | bc17 | C++ Programming | 10 | 11-24-2002 12:20 PM |
| simulate Grep command in Unix using C | laxmi | C Programming | 6 | 05-10-2002 04:10 PM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |