0
我有類似下面的代碼東西在我的應用程序:結構,指針,該指針獲取字段值
#include <stdlib.h>
#include <stdio.h>
typedef struct STH
{
double *buff;
int size;
}STH;
void fun1(STH *s)
{
fun3(s->buff, s->size);
}
void fun3(double *buff, int n)
{
int i = 0;
printf("N = %d\n", n);
for(i=0; i<n; i++)
printf("%d\n", buff[i]);
}
void fun2()
{
STH s;
s.size = 4;
s.buff = malloc(sizeof(double) * s.size);
fun1(&s);
}
int main()
{
fun2();
return 0;
}
當我試圖打印出fun3
緩衝區,gdb
說有一個錯誤在fun3
。當我嘗試打印出(fun2
)s->size
的值時,出現錯誤(而不是4,它打印出奇怪的數字....)
「%f \ n」,s.buff = calloc(s.size,sizeof(double)) – BLUEPIXY
fun3(..){..} before fun1(..){..} – BLUEPIXY