프로그래밍

 3198, 1/160 회원가입  로그인  
   rocket07
   http://--
   malloc과 free 함수에 관한 코드 질문ㅜ

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=3288 [복사]


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
        char *str;
        int num, i;

        printf("당신의 ID는 몇글자 입니까\n");
        scanf("%d", &num);

        str = (char *) malloc (sizeof(char) *num+1);
        if(!str){
                printf("메모리를 확보할 수 없습니다\n");
                return 1;
        }
        
        scanf("%s", str);

        printf("%s\n", str);

        free(str);
        return 0;
}

str 이라는 char 형 배열에 제가 원하는 만큼의 크기를 할당할려고 하는데.. 저렇게 입력하고 디버깅해보면

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: _WinMain@16 외부 기호(참조 위치: ___tmainCRTStartup 함수)에서 확인하지 못했습니다.
1>C:\Users\lgepc\Desktop\파일\Debug\파일.exe : fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다.


이렇게 오류가 두개 떠요.  왜이런거죠??;

  Hit : 4900     Date : 2012/01/20 12:57



    
key Console Application 으로 프로젝트를 생성하시면 됩니다. 2012/01/20  
rocket07 Console Application 가 뭔가요? 그리고 왜 그냥하면 안되는거죠?? 2012/01/20  
start3r 비쥬얼 스튜디오에서 처음 프로젝트를 생성할 때, Windows Application을 선택한 것 같습니다. Win App 프로젝트를 선택하면 프로그램의 진입점(entry)으로 WinMain()을 찾습니다.

쉬운 해결책은 프로젝트를 다시 생성하시고, 프로젝트 생성시 console application 으로 선택하여 생성한 뒤 프로그래밍을 하시면 잘 될 듯 싶네요.^^
2012/01/31