samedi 20 septembre 2014

I'm getting segmentation fault error in terminal (on mac) for a simple program


Vote count:

0




I'm trying to implement the ls command in terminal by writing out the code but I am getting 'Segmentation fault' error. I have no idea why. I've been trying to figure it out all day :(



#include "sys/types.h"
#include "dirent.h"
#include "stdio.h"

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

DIR *dp;

struct dirent *dirp;

if (argc == 1)
dp == opendir("./");
else
dp == opendir(argv[1]);

while( (dirp=readdir(dp)) != NULL)
printf("%s\n",dirp -> d_name);

closedir(dp);


return 0;
}


asked 22 secs ago







I'm getting segmentation fault error in terminal (on mac) for a simple program

Aucun commentaire:

Enregistrer un commentaire