C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-13-2009, 04:21 PM   #1
Registered User
 
Join Date: Jan 2009
Posts: 37
Post Specify a path for write file

Hi
i'm having this function:

Code:
int logger(char *log_prefix,char *buffer)
{
	printf("Logger: Logging Command...\n");
	time_t now;
	time(&now);
	FILE *file;
	file = fopen("log.txt","a+"); // apend file (add text to a file or create a file if it does not exist.
	//writes the "buffer" to the txt file and current time and log prefix ( either sent or received).
	fprintf(file,"Time/Date:%s# Command %s = %s\n",ctime(&now), log_prefix,buffer);
	fclose(file);
	printf("Logger: Command Logged, Check log.txt for more details.\n");
	return 0;
}
this function creates a txt file called log.txt, in the path that the .c file exist. how can i specify a path in which the file will be created?

this code
Ali.B is offline   Reply With Quote
Old 08-13-2009, 04:26 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
By specifying the filename you want created. If you want "../other_dir/log.txt", then say so.
tabstop is offline   Reply With Quote
Old 08-13-2009, 04:36 PM   #3
Registered User
 
Join Date: Jan 2009
Posts: 37
Yes...

Code:
file = fopen("./path/log.txt","a+");
this is what i needed to change, thanks for the help
Ali.B is offline   Reply With Quote
Reply

Tags
file, path, write

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A development process Noir C Programming 30 10-28-2009 04:24 AM
Problems passing a file pointer to functions smitchell C Programming 4 09-30-2008 02:29 PM
sequential file program needhelpbad C Programming 80 06-08-2008 01:04 PM
archive format Nor A Brief History of Cprogramming.com 0 08-05-2003 07:01 PM
simulate Grep command in Unix using C laxmi C Programming 6 05-10-2002 04:10 PM


All times are GMT -6. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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