Here's my entire code. Sorry, I don't know why I didn't do this before:
Code:
#include <stdio.h>
#include <string.h>
#define TOTAL_CLASSES 50
#define TOTAL_PREREQUISITES 5
#define NAME_LENGTH 6
main() {
char *courses[TOTAL_CLASSES];
char buf[BUFSIZ];
char *tok;
char *crslist[TOTAL_CLASSES][TOTAL_PREREQUISITES];
int position = 0;
int numCourses = 0;
int coursesAdded = 0;
int i;
int j = 1;
int k;
// add all courses to array of courses
while ( fgets(buf, BUFSIZ, stdin) ) {
for (tok = strtok(buf, " "); tok != NULL; tok = strtok(NULL," ")) {
courses[position] = strdup(tok);
numCourses++;
position++;
}
}
// add courses
for (i = 0; i < numCourses; i++) {
for (k = 0; k <= i; k++) {
if (crslist[k][0] != NULL) {
if (strcmp(crslist[k][0],courses[i])) break;
else continue;
}
else crslist[k][0] = courses[i];
}
}
printf("%s ", crslist[0][0]);
}
With this, I get something in the crslist[0][0] position, but when I try to print crslist[1][0], I get really weird looking characters. Here for more information on the problem, you can go here: http://www.cs.dal.ca/~sedgwick/2132/a3/problem