Pointer issues in C

Joined
Jul 26, 2011
Messages
1
Reaction score
0
hello there
I'm new to programming and i was writing a c program that would take in a directory as an argument and give me all the files of the directory. Here's the codes:

#include <stdio.h>
#include <string.h>
#include <dirent.h>

int main(int argc, char* argv[])

{


DIR* dir;
struct dirent* entry;

if (argc != 2 || !argv[1]){
printf ("please enter a path");

dir=opendir(argv[1]);
if (!dir) {
perror("opendir");
}
printf("Directory contents:\n");
while ( (entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}

}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top