fopen with file location

Discussion in 'C' started by Poonamol, Apr 9, 2010.

  1. Poonamol

    Poonamol New Member

    Joined:
    Mar 31, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I am creating/opening a file using,

    FILE *file = fopen(" C:\\ABC\\Poo.txt","w+");
    if(file == NULL)
    printf("un sucessful");
    else
    printf("sucessful");

    I am able to create a file name poo.txt on C:\ABC folder.

    Now I used,
    #define PATH "C:\\ABC\\"
    FILE *file = fopen(" PATH+Poo.txt","w+");
    OR
    #define PATH "C:\\ABC"
    FILE *file = fopen(" PATH\\Poo.txt","w+");
    if(file == NULL)
    ........

    How can I use PATH constant with file name in fopen?

    Help me out ASAP.
    Thanks in advance.
     
  2. karthigayan

    karthigayan New Member

    Joined:
    Feb 19, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    I tried this in linux machine.We can do this .

    You have to mention like the following ,

    Code:
            FILE *file=fopen(PATH"/file.txt","r+");
    
    Don't place the PATH inside the double quotes , because what ever inside the double quotes will treated as a string.
     
  3. Poonamol

    Poonamol New Member

    Joined:
    Mar 31, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    Thank you so much for the reply.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice