//insert a thread at the list void insertThread(threadList* list, tcb* thread) { ////printf("insert thread %d\n", thread->tid); ////printf("status da thread %d\n", thread->status); if(alreadyInList(list, thread->tid)) { ////printf("already in list!!!!\n"); return; } if(list->first == NULL && list->last == NULL) { list->first = thread; list->last = thread; } else if(list->first == NULL && list->last != NULL) { ////printf("ERRO 1 %d!\n", thread->tid); } else if(list->first != NULL && list->last == NULL) { ////printf("ERRO 2 %d!\n", thread->tid); } else { list->last->next = thread; list->last = thread; } ////printf("inserted %d!!!!\n", list->last->tid); list->count++; }
int main() { char buf[BSIZE]; FILE* list = fopen("emlist.txt", "a+t"); if(list == 0) { perror("could not open emlist.txt"); exit(1); } while(1) { gets(buf); /* From stdin */ if(alreadyInList(list, buf)) { printf("Already in list: %s", buf); fflush(stdout); } else { fseek(list, 0, SEEK_END); fprintf(list, "%s\n", buf); fflush(list); printf("%s added to list", buf); fflush(stdout); } } } ///:~