C编程的两个死角请问,
C编程的两个死角请教,急。。。。
1,在devC++4.9.9.2下,我先定义了一个结构体:
typedef struct {
char* ch;
int length;
}*test;
然后在main()中建立两个test类型的指针,如下:
test s;
test t;
。。。。
编译无法通过,原因是是建立了多个test类型的指针,如果只建立一个的话,是可以通过的。。。为什么呢?
2,我编写了一个子函数,其中有一句是:
if(1){
printf( "%d,%d ",s-> length,t-> length);//输出10,23
s-> ch = (char*)realloc(s-> ch,s-> length+t-> length+1);
if(!s-> ch) exit(0);
printf( "%d,%d ",s-> length,t-> length);//输出10,42
郁闷,我什么时候把他们的值改变了呢??
------解决方案--------------------
编译器的问题
1,在devC++4.9.9.2下,我先定义了一个结构体:
typedef struct {
char* ch;
int length;
}*test;
然后在main()中建立两个test类型的指针,如下:
test s;
test t;
。。。。
编译无法通过,原因是是建立了多个test类型的指针,如果只建立一个的话,是可以通过的。。。为什么呢?
2,我编写了一个子函数,其中有一句是:
if(1){
printf( "%d,%d ",s-> length,t-> length);//输出10,23
s-> ch = (char*)realloc(s-> ch,s-> length+t-> length+1);
if(!s-> ch) exit(0);
printf( "%d,%d ",s-> length,t-> length);//输出10,42
郁闷,我什么时候把他们的值改变了呢??
------解决方案--------------------
编译器的问题