我已經寫了這段代碼在這裏,我已經鏈接它與一些其他功能和一個主要的好,它沒有任何問題和編譯沒有警告(我正在使用gcc編譯器)。無法打印字符串單鏈表的內容
我使用指針數組(archive.products [])作爲多個字符串列表的入口點。我還處於開始階段,因此列表中每個節點只有一個節點。
我得到的問題是,我無法讓函數lprintf在屏幕上顯示我創建的單節點字符串列表組件。請注意位於推送功能內的printf可以打印。所以我知道,推是做它的工作...
如果任何人有任何想法,我可能會做錯什麼,請在下面的回覆。 提前感謝您!
#define line_length 61
#define max_products 10
struct terminal_list {
char terminal[line_length];
struct terminal_list *next;
}*newnode, *browser;
typedef struct terminal_list tlst;
struct hilevel_data {
char category[line_length];
tlst *products[max_products];
};
typedef struct hilevel_data hld;
void import_terms(FILE *fp, hld archive){
char buffer[line_length];
char filter_t[3] = "}\n";
int i = 0, j = 0;
while (!feof(fp)) {
fgets(buffer, line_length, fp);
if (strcmp(buffer, filter_t) == 0) {
return;
}
head_initiator(archive, i);
push(buffer,archive, i);
lprintf();
i++;
}
}
void head_initiator(hld archive, int i){
browser = NULL;
archive.products[i] = NULL;
}
void push(char buffer[],hld archive, int i){
newnode = (tlst *)malloc(sizeof(tlst));
strcpy(newnode->terminal, buffer);
// printf("%s", newnode->terminal);
archive.products[i] = browser;
newnode->next = browser;
browser = newnode;
}
void lprintf(){
tlst *p;
p = browser;
if (p = NULL){
printf("empty\n");
}
while(p!=NULL){
printf("%s\n", p->terminal);
p=p->next;
}
}
哦,親愛的上帝,非常感謝!在我的鼻子下! – 2011-01-07 17:56:07