command line argument to accept entire directory
I am writing a program called mywc that mimics a scaled back version of wc. It accepts as command line arguments file(s) and tallies the number of characters, words and lines in that file(s). My particular problem is that I want it to accept all files from the current directory if the user enters "mywc *" rather than having them type out all the files by name. I'm sure that it is possible, but I'm not sure how to do it. Thanks.
Issuing system calls in UNIX
The mywc program would, ideally, work in both OSs. However, this is not an ideal world and I'm still unfamiliar with what works in one OS and not in another. Thanks to your post, I was able to do a search and find the post below. I haven't been able to try it yet, but will shortly. Thanks, vsriharsha, for your help.
************************************************** **
If you are using a POSIX operating system (UNIX, Linux, etc) you would use opendir() and readdir() to get the directory information. You need to include sys/types.h and dirent.h to use these functions. Here are the function prototypes:
code:-----------------------------------------------------------------------------
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dir);
------------------------------------------------------------------------------------
Pry open the dirent.h header file for the details in the dirent structure (I'm not in front of a *nix system at the moment, and my memory is failing).
When you are finished with the directory, be sure to call closedir():
code:-----------------------------------------------------------------------------
int closedir(DIR *dir);
------------------------------------------------------------------------------------
Hope that helps.
- Jason Deckard