gcc에서 struct선언을 어떻게 하나요?
글쓴이: 이상훈 / 작성시간: 일, 2003/07/27 - 12:29오전
gcc를 처음 써보는데, struct선언을 했다가 계속 에러 나길래 테스트 코드를 짜봤읍니다.
#include<stdio.h>
#include<stdlib.h>
struct ttt
{
int a;
char b;
};
typedef struct ttt ttt;
typedef struct ttt* _ttt;
_ttt te;
int main()
{
te= (_ttt)malloc(sizeof(ttt));
te.a = 1;
te.b = "abc";
printf("%d%s",te.a,te.b);
free(te);
return 0;
}
이렇게 해봤는데.... 머가 문제인가요?=_=
초보라서 알 길이 없네요..ㅠㅠ
Forums:


Re: gcc에서 struct선언을 어떻게 하나요?
#include<stdio.h> #include<stdlib.h> struct ttt { int a; char b; /* 의도한 목적이라면 char *b; 가 맞습니다. */ }; typedef struct ttt ttt; typedef struct ttt* _ttt; _ttt te; int main() { te= (_ttt)malloc(sizeof(ttt)); te.a = 1; /* (*te).a 또는 te->a 가 맞습니다 */ te.b = "abc"; /* (*te).b 또는 te->b가 맞습니다 */ printf("%d%s",te.a,te.b); /* 여기도 마찬가지 */ free(te); return 0; }감사합니다.(^^)(__)
ㄳㄳ
댓글 달기