int addCommand(Commands c, char* command, int index) { printf("Requested Index %d\n", index); char** commands; char* newCommand; commandNode ptr; int i; if (c == NULL) { return -1; } if (index > c->size) { return -1; } if (c->head == NULL) { printf("Empty Head\n"); commands = initializeArray(50); newCommand = createWord(command, 0, strlen(command)); commands[0] = newCommand; printf("New Word is %s\n", newCommand); c->head = createNode(commands); c->size++; } else { printf("Moving!\n"); ptr = c->head; for (i = 0; i < index; i++) { ptr = ptr->next; } if (ptr == NULL) { printf("Adding To new Node\n"); commands = initializeArray(50); newCommand = createWord(command, 0, strlen(command)); commands[0] = newCommand; c->head = addToList(c->head, createNode(commands)); c->size++; } else { printf("Adding to exisiting Node\n"); newCommand = createWord(command, 0, strlen(command)); ptr->command[ptr->size] = newCommand; ptr->size++; } } return 1; }
int main() { const int lengthArray = 30000; Word **m = createArray(lengthArray); FILE *f = fopen("input.txt", "r"); while (!feof(f)) { char s[50]; scanWord(s, f); if (s[0] != '\0') { unsigned int a = hashFunc(s, lengthArray); if (m[a] == NULL) m[a] = createWord(s); else { Word *tmp = m[a]; while ((tmp->next != NULL) && (strcmp(tmp->s, s) != 0)) { tmp = tmp->next; } if (strcmp(tmp->s, s) == 0) tmp->repeats++; else tmp->next = createWord(s); } } } fclose(f); for (int i = 0; i < lengthArray; i++) { if (m[i] != NULL) { Word *tmp = m[i]; while (tmp != NULL) { printf("%s - %i\n", tmp->s, tmp->repeats); tmp = tmp->next; } } } clear(m, lengthArray); delete[] m; scanf("%*"); return 0; }