וואלה צודק!
הרצתי שוב וזה לא עף... כנראה זו היתה טעות קטנה שסידרתי אותה בלי לשים לב אני מצרפת חלק מהתוכנית- הבעיה היא כאשר מקלידים: בשורה הראשונה- NURIT בשורה השניה- !! (כלומר- הMAIN שולח לANALIZE_HISTORY ומשם לFIND_HISTORY_N) ניסיתי כבר פעמיים לצרף את הקובץ, וכל פעם זה נכשל, אז שמתי אותו כאן,למרות שלדעתי זה יותר מידי לא ברור... (לא הצלחתי לגלות איך ליישר הכל לשמאל..) תודה רבה! #include <math.h> #include "data.h" struct history_list l_history; struct history_link *f; char ErrMsg[MAX_BUF+1]; ///////////////////////////////////////////////////// // Initilize the history list. ///////////////////////////////////////////////////// void InitilizeHistory(struct history_list* l) { if (l != NULL) { l->head = NULL; l->tail = NULL; l->len = 0; l->max = 100; } } ///////////////////////////////////////////////////// // free the history list. ///////////////////////////////////////////////////// void FreeHistory(struct history_list* l) { struct history_link* temp; if (l != NULL) { while(l->head) { free(l->head->command); temp = l->head->next; free(l->head); l->head = temp; } } } ///////////////////////////////////////////////////// // Print the history list. ///////////////////////////////////////////////////// void PrintHistory(struct history_list* l) { struct history_link* temp = l->head; while(temp) { printf(" %d\t%s\n", temp->lid, temp->command); temp = temp->next; } } ///////////////////////////////////////////////////// // find a record from history list by location. ///////////////////////////////////////////////////// char * FindHistoryN(struct history_list* l, int n) { struct history_link* temp = l->tail; int i=0; if (n>l->len) return NULL; while(temp) { i++; if (i == n) return temp->command; temp = temp->prev; } return NULL; } void RemoveStart(struct history_list* l) { struct history_link* temp; // Delete the last history. temp = l->head->next; free(l->head->command); free(l->head); l->head = temp; if (temp != NULL) temp->prev = NULL; l->len--; } void AddEnd (struct history_list* l,struct history_link * temp) { if (temp->command != NULL) { // Set the new link to be the head. temp->prev = l->tail; temp->next = NULL; if (1 <= l->len) l->tail->next = temp; else l->head = temp; l->tail = temp; l->len++; } } ///////////////////////////////////////////////////// // Add a command to the history list. ///////////////////////////////////////////////////// void AddHistory(struct history_list* l, char* command, int lid) { struct history_link* temp; if (l->len>=l->max) RemoveStart(l); // Allocate new link. temp = (struct history_link*)malloc(sizeof(struct history_link)); if (temp != NULL) { // Allocate and Copy string to the command. temp->lid = lid; temp->command = strdup(command); } AddEnd(l,temp); } /***************************************** RETURN VALUE: 1: O.K, add the new str to history -1: the com failed. go to the next com 0: wrong input ****************************************/ int AnalizeHistory (char * com) { char * pNum; int iNum; char * new_com; if (com[0]=='!') { if (com[1]=='!') { if (new_com=FindHistoryN(&l_history,1)) { free(com); com=strdup(new_com); return 1; } else return -1; } } return 1; } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// ///////