Essentially I am having a very basic problem... A little new at C. I'm making a node structure that stores a name (string) and its type (char, either 'D' or 'F'). The string works fine, the char doesn't seem to.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char line[128];
char command[16], pathname[64];
char dirname[64], basename[64];
typedef struct {
char name[64];
char type;
struct NODE *childPtr, *siblingPtr, *parentPtr;
} NODE;
NODE *root, *cwd;
initialize(){
root = malloc(sizeof(NODE));
strcpy(root->name, "/");
root->type = 'D';
}
main()
{
while(1){
printf("Input a command: ");
gets(line);
printf("Command inputed -> %s\n", line);
printf("Root's name -> %s\n", root->name);
printf("Root's type -> %c\n", root->type);
}
}
Now when I do this, it prints out the name just fine, but Segmentation Faults on the line that should print the type. I also tried defining type with "root.type = 'D';" as well.
EDIT: Copy pasted exact code now. Some things have no use since I am just testing the first part of it, still a work in progress.