Using fopen() with array containing path

This is a discussion on Using fopen() with array containing path within the C Programming forums, part of the General Programming Boards category; How would I use fopen() when the path I need to open the file is stored in a array instead ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    96

    Using fopen() with array containing path

    How would I use fopen() when the path I need to open the file is stored in a array instead of a char *

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    assuming you have

    char filename[19] = "c:\whatiswrong.txt";
    FILE * MyFile;

    then you can just use
    MyFile = fopen(filename, "w");

    just as if you declared filename as a char *

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why do you think it would change?

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    how is it stored in the array? if it's a char array with only one path then it's no different from a char*.
    Code:
    char path[] = "/path/file";
    fp = fopen(path, "r");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 01:44 AM

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