Hello

I was wondering whether is it possible to create a .txt file or check if a .txt file exists inside the folder earlier defined as a path.
Basically I have a path :

#define some_little_file "/User/Joey/Desktop/"

and I would like to create and manipulate a txt file there.
Is it even possible??
Merry Christmas btw guys much love !!

Yup ...

if (file = fopen(file_name, "r"))
{
       printf("Exists");
       fclose(file);
}

Merry Christmas to u too ...

Yup ...

if (file = fopen(file_name, "r"))
{
       printf("Exists");
       fclose(file);
}

Merry Christmas to u too ...

Thanks for your answer

I know how to work with files in c, but my problem is that I need to create a file on that path. My source is on a external disk or whatever and I want it to create a txt file on my desktop. I just need to know whether is it possible without using cmd arg.

Your program can create a file anywhere it wiches as long as it has the permissions needed to do that. You can't create a file in a directory where you don't have write permissions.

Or are you trying to ask if you can put the path in a file and read the path from that file. For example, if you have file named ./path that contains "/User/Joey/Desktop/". The answer is again yes, you can easily do that. Just read the file into a variable the use that variable in the call to fopen()

commented: Gr8 guy !! +1

Your program can create a file anywhere it wiches as long as it has the permissions needed to do that. You can't create a file in a directory where you don't have write permissions.

Or are you trying to ask if you can put the path in a file and read the path from that file. For example, if you have file named ./path that contains "/User/Joey/Desktop/". The answer is again yes, you can easily do that. Just read the file into a variable the use that variable in the call to fopen()

Thank you ancient dragon. Much respect !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.