hokieghal99 wrote:[color=blue]
> I wish to place all files and directories that are within a user defined
> path (on a Linux x86 PC) into some type of array and then examine those
> items for the existence of certain charaters such as "*?<>/\|\\" If one
> of the chars are found, I'd like to replace it with a "-" and then
> commit the change to the actual file system. I know that a scripting
> language may be better suited for this, but I'm experimenting with C and
> I'm trying to learn how to better use it. Here are my questions:
>
> 1. How would I collect all of the file and dir names from a specific path?[/color]
You would have to use platform specific functions. The _standard_ C++
language has no facilities for or requirements of directories. Ask the
experts in a newsgroup about your platform.
[color=blue]
> 2. What type of array should I place them in?[/color]
Text is often represented as a array of characters terminated by a
nul character ('\0'). Many of the string functions expect the
terminating null character. See strcpy, strstr, strcat. Also,
beware of the '\' backslash character, since it represents an
"escape" character. The common pitfall is to have a filename of
"any_directory\text.txt", where the '\t' represents a tab character
in C.
If you want multiple text objects, you may want an array of (array
of text), e.g.:
char many_texts[20][128];
char * * p_many_texts;
[color=blue]
>
> Here is why I ask the second question. I know that C has no built-in
> type for strings. I know that it uses a char array to make a string. So,
> a filename would be a char array (string), right? This is where I do not
> understand how to create an array of char arrays (strings). Any
> pointers? I am new at C, so forgive my ignorance.
>
> Thanks!!!
>[/color]
Read the C FAQ below.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library