It would do you a dis-service to just give you code to solve your homework problem. However thank you for being clear that it is homework. I am happy to point you in the right direction.
The function calls you need to know about to get directory listings are:
These are part of the standard C library. You can get detailed documentation on each by looking in section 3 of the manual. e.g. to see the documentation for opendir, open a terminal and enter the command:
You might also need to use access (which is a system call, and as such is documented in section 2 of the manual).
To build a C program, you can use the gcc
program (this stands for GNU C Compiler). C++ programs are built using g++
. Assuming your program code is all in one file called myprog.c, the command to compile and link is simply:
gcc -g myprog.c -o myprog
The -g includes debugging symbols in your binary which makes it possible to trace the code using gdb
(the GBU DeBugger).