开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
VS2010
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
standard lib.
问题(Question):
我将结构的位址传入副程式,却无法在主程式使用
程式码(Code):(请善用置底文网页, 记得排版)
//linklist.h
struct list{
int num;
struct list *nx;
};
typedef struct list node;
//main.c
#include<stdlib.h>
#include<stdio.h>
void create(node *top, node *previous, node *current);
int main(){
node *top,*previous,*current;
top=previous=current=NULL;
create(top,previous,current);
printf("first data is %d\n",top->num);
printf("second data is %d\n",top->nx->num);
system("pause");
return 0;
}
void create(node *top, node *previous, node *current){
int i;
for(i=0;i<3;i++){
current = (node *)malloc(sizeof(node));
current->nx=NULL;
printf("Enter num");
scanf("%d",¤t->num);
if(top==NULL)
top=NULL;
else
previous->nx=current;
previous=current;
}
}
补充说明(Supplement):
print出来的值都是NULL
怎么会这样呢?传递过去不是都是内存位置?理论上来说在主程式或是副程式修改都没问题
是不是我哪边忽略了?我才刚开始学资料串结,拜托帮帮我,别砲新手,谢谢