포인터에 대해 급하게 질문있습니다ㅠㅠㅠ
가지등
질문 제목 : 포인터에 대해 급하게 질문있습니다ㅠㅠㅠ전역변수를 사용하지 않고, 구조체배열을 서로다른 파일(test1, test2)에서 값을 공유하면서 이용하고 싶은데 어떻게해야될까요?질문 내용 :
전역변수를 사용하지 않고, 구조체 배열을 서로다른 c파일에서 이용하고싶습니다.
만약에 test1.c에서 구조체배열을 선언했다면, 이 값을 test2.c에서 그대로 이용하고, test2.c에서 값을 바꾸면 자동적으로 test1.c에서 값이 변경되도록 해야하는데 어떻게해야될지 모르겠습니다ㅠㅠㅠㅠ//////////////test1.h///////////////
typedef struct test
{
char* str;
int n;
} test;
test* init();
void printtest(test* t);//////////////test1.c///////////////
#include stdio.h
#include test1.h;
test* init()
{
test t[2] = {{a, 1}, {b, 2}};
test* pt = t;
return pt;
}
void printtest(test* t)
{
printf(%s %s, t[0].str, t[1].str);
}//////////////test2.h///////////////
void change();//////////////test2.c///////////////
#include stdio.h
#include test1.h
void change()
{
test* t2 = init();
t2[0].str = aa;
printf(%s %s\n, t2[0].str, t2[1].str);
}//////////////main.c///////////////
#include stdio.h
#include test1.h
#include test2.h
int main(void)
{
init();
change();
printtest(init());
}
임시로 해본소스는 위와같습니다..일단 실행도 제대로 안되네요..
위에서 잘못된부분좀 고쳐주시고, 설명도 부탁드립니다ㅠㅠㅠ
몇일때 이거때문에 헤매고있네요ㅠㅠㅠ꼭 부탁드립니다ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ