making a file_write function

This is a discussion on making a file_write function within the C Programming forums, part of the General Programming Boards category; 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 ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,458
    you have missed quot in the second example
    "wt" - should it be

    next time - post your errors as well
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 12:03 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Replies: 5
    Last Post: 02-08-2003, 06:42 PM

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