Friday, January 6, 2012

fopen example in c


2 comments:

  1. Hi,
    How can I create a file from diferent directory?
    I already tried with the full path, like this:

    fp = fopen( "\\dir1\\dir2\\ccplusplus.com", "wt" );

    Can anyone help me please?
    Thanks

    ReplyDelete
    Replies
    1. Assuming you are running your program on Linux, here will be the code change that you should be using,

      fp = fopen( "/tmp/ccplusplus.com", "w" );

      or fp = fopen( "/tmp/ccplusplus.com", "w+" );

      in your code you have used,

      fp = fopen( "\\dir1\\dir2\\ccplusplus.com", "wt" );

      which seems to be a windows specific.

      Thank you

      Delete