Thread: making a file_write function

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    12

    making a file_write function

    Hello,

    Currently I use the following code which works.
    Code:
    void file_write (){
    	FILE *file;
    	
    	file = fopen("c:\\windows\\Temp\\poop\\toadd.txt", "wt");
    	fprintf (file, "%s", "\nWritten by John");
    	fclose (file);
    }
    However I would like to change it so I can reuse it. I want to be able to pass in a file_path and text_to_write
    Code:
    file_write (char[] file_path, char[] text_to_write){
                    FILE *file;
    	
    	file = fopen(file_path, wt");
    	fprintf (file, "%s", text_to_write);
    	fclose (file);
    }
    However I don't believe this is the correct way to do it? I get errors. How can I do this?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you have missed quot in the second example
    "wt" - should it be

    next time - post your errors as well
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM