我已经在这里写了这段代码,我已经将它与其他几个函数和一个main链接起来,它正在工作,没有问题,并且没有任何警告(我使用的是gcc编译器)。
我使用指针数组(archive.products[])作为多个字符串列表的入口点。我还处于初级阶段,所以每个列表只有一个节点。
我遇到的问题是,我无法让lprintf函数在屏幕上显示我创建的单节点字符串列表的组件。请注意,位于push函数内部的printf可以正常打印。所以我知道push正在做它的工作...
如果有人知道我可能做错了什么,请在下面回复。提前谢谢你!
#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-08 01:53:47
On:void lprintf()
if (p = NULL)应该是
if (p == NULL)发布于 2011-01-08 01:53:26
if (p = NULL){
printf("empty\n");
}我想你的意思是
if (p == NULL){
printf("empty\n");
}您实际上是在用p = NULL清空列表。
https://stackoverflow.com/questions/4628570
复制相似问题