Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   fopen with file location (http://www.go4expert.com/forums/fopen-file-location-t21716/)

Poonamol 9Apr2010 11:13

fopen with file location
 
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.

karthigayan 9Apr2010 15:05

Re: fopen with file location
 
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.

Poonamol 9Apr2010 15:07

Re: fopen with file location
 
Thank you so much for the reply.


All times are GMT +5.5. The time now is 05:00.