Code: mode = (char *) malloc(sizeof(char*)); What are you allocating here?
mode = (char *) malloc(sizeof(char*));