hi.
question 1:
i am writing a small C script to convert files to another format.
in this case i need my script to use all files in a directory that have extension .htm - how can i do this?
the user will manually specify the directory path but then i want the software to find all .htm files and take their contents to paste them in another file

question 2:
after the user wrote the directory's path (eg. /home/frank/mywebsite) it will save it in a char variable.
when i need to open a certain file I have to specify the path myself, like this

fp = fopen("/var/tmp/string.txt", "r")

but now can i do this

fp = fopen("user_path/some_file.htm", "r")

?

>i need my script to use all files in a directory
You can search a directory with opendir and readdir and closedir. Check your man pages for details.

>but now can i do this
You need to build the path string manually:

char user_path[] = "user_path";
char filename[] = "some_file";
char full_path[BUFSIZ];

sprintf ( full_path, "%s/%s.htm", user_path, filename );

fp = fopen ( full_path, "r" );
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.