Thread: problem with fopen command

  1. #1
    Registered User
    Join Date
    Mar 2004

    problem with fopen command

    i'm writing a program where i'm supposed take the name of a file with it's full path which will be fed by the user.then i'm supposed to store it in an array of charecters.then i'm supposed to use the fopen command to open file where the file name would be the one that is stored in the previous array.but the problem is that fopen only accepts strings within double quotes like following:

    File *f;

    that's why i cannot pass my array as the first parameter for the fopen what can i do to have the work done(take the file name specified by the user and using that name open that file using fopen).i' also taking care of the double \\ in my array.plzzzzz help....

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >but the problem is that fopen only accepts strings within double quotes
    fopen doesn't care if the string is a string literal or a pointer to a string literal or an array of char terminated by '\0'. The following is perfectly acceptable:
    char *name = "/me/dir/file";
    FILE *out = fopen ( name, "w" );
    My best code is written with the delete key.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    don't forget to take out the \\ if you are in windows and also don't forget the \n if you use fgets to get the filename Ex:
    printf("Enter a file:  ");
    fgets(input,sizeof input,stdin);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. command line parameters problem...
    By ac251404 in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2006, 12:44 PM
  3. in program command console
    By howzer in forum C++ Programming
    Replies: 11
    Last Post: 03-19-2006, 02:12 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 11:54 AM
Website Security Test