I am not sure why I am getting a seg fault. I know it is somewhere in my pidspec function but I'm not sure why it is happening. The goal of this program is to have the process id passed in as first argument to program, from there, the pid is located in the proc folder and the contents of that file are displayed to console. Any help would be greatly appreciated. I haven't written any C for a year so I'm a bit rusty.
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
void pidspec(char *v){
DIR *myDirectory;
struct dirent *myFile;
char *proc = "/proc";
printf("Made it here");
myDirectory = opendir(proc);
if(myDirectory){
printf("Made it here");
if(strcmp(myFile->d_name, v) == 0){
myDirectory = opendir(v);
if(myDirectory){
while ((myFile = readdir(myDirectory)))
printf("%s\n", myFile->d_name);
}
}
}
return;
}
int main(int argc, char *argv[]){
printf("Made it here");
if(argc == 2){
printf("%s",argv[1]);
pidspec(argv[1]);
}
return 0;
}