I'm getting a seg-fault in the following code: strcat seems to be throwing the fault.
I don't understand why that is the case because I am putting strings into both arguments
Code:
struct procinfo { char *file; char *info;};
int procSize = 3;
int procCount= 0;
char *file = "1.txt";
FILE *fp;
struct procinfo procs[] = {
"status", "Pid",
"status", "PPid",
"environ", "USER=",
};
int main(void){
DIR *d;
struct dirent *dir;
if (chdir("/proc")!=0)
printf("Directory Not Found Properly"); //Set current directory to /proc
d = opendir(".");
if (d){
while ((dir = readdir(d)) != NULL){
procCount = 0;
if(isdigit(dir->d_name[0])){//If directory starts with a number
printf("PROCESS: %s\n", dir->d_name);
while(procCount < procSize){
file = "/proc/";
strcat(file, dir->d_name);
printf("%s\n = file", file);