Specify a path for write file

This is a discussion on Specify a path for write file within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    39

    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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    By specifying the filename you want created. If you want "../other_dir/log.txt", then say so.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    39
    Yes...

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

Tags for this Thread


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