#include <stdio.h>
struct IntData
{
int n1;
int n2;
};
struct StrData
{
char str1[20];
char* str2;
};
void main()
{
struct IntData di, *dip;
struct StrData ds, *dsp;
dip = &di;
dsp = &ds;
scanf("%d %d\n",dip->n1,dip->n2);
scanf("%s %s\n",dsp->str1,dsp->str2);
printf("%d %d\n",dip->n1,dip->n2);
printf("%s %s\n",dsp->str1,dsp->str2);
}
정수두개와 문자열 두개를 입력받아서 출력시키는 소스인데
오류가 발생하는 부분과 알맞은 코드로 수정하라고 합니다.
저는 struct IntData di, *dip;이 부분이 전혀 그림이 안그려지네요
dip라는 포인터 변수로 구조체가 이루어 진다는게 뭔지 전혀 모르겠네요
scanf("%d %dn",&dip;->n1,&dip;->n2); scanf("%s %sn",dsp->str1,dsp->str2 = malloc(120));
감사합니다. 동적할당을 하지 않고서는 방법이없을까요?
str2에 포인터말고 적절한크기의 배열로 잡아두셈
마지막줄은 int포인터가 int형만 참조할수 있는 원리랑 같은건데.. 자료형에따라 크기가 다르니까 참조할 타입을 정해주는거임 발에 너무 크지도않고 작지도않은 딱맞는 신발 이라고 생각하면 될듯 ㅋㅋ