#include <stdio.h>
#include <stdlib.h>
struct sdata {
int *a;
float *b;
double *c;
char *d;
};
struct sdata* input();
int main() {
struct sdata indata;
in>
return 0;
}
struct sdata* input() {
struct sdata* temp_data;
int i;
temp_data->a = (int*)malloc(sizeof(int) * 2);
temp_data->b = (float*)malloc(sizeof(float) * 2);
temp_data->c = (double*)malloc(sizeof(double) * 2);
temp_data->d = (char*)malloc(sizeof(char) * 10);
for (i = 0; i < 2; i++) {
printf(" a[%d] 값 입력 : ", i);
scanf_s("%d", &temp_data->a[i]);
printf(" 입력된 a[%d]의 값 : %d
", i, temp_data->a[i]);
}
for (i = 0; i < 2; i++) {
printf(" b[%d] 값 입력 : ", i);
scanf_s("%f", &temp_data->b[i]);
printf(" 입력된 b[%d]의 값 : %f
", i, temp_data->b[i]);
}
for (i = 0; i < 2; i++) {
printf(" c[%d] 값 입력 : ", i);
scanf_s("%lf", &temp_data->c[i]);
printf(" 입력된 c[%d]의 값 : %lf
", i, temp_data->c[i]);
}
printf(" 문자열 d 입력 : ");
scanf_s("%s", temp_data->d, 10);
printf(" 입력된 d의 값 : %s
", temp_data->d);
return temp_data;
}
여기서 temp_data가 초기화 되지 않은 지역변수래요...
왜 안되는건가요? 어떻게 해야하는건가요?
초기화같은걸하나?
래서 저기 temp_ 0, } 으로 해봤는데도 프로그램이 터지더라구요.
왜 댓글이 이상하게 달리지;
malloc 찾아봐라
또는 C언어 동적 메모리 할당
그리고 동적 메모리 해제 로도 찾아보구
free 라는 함수도