문자열배열, 포인터배열 warning writing into constant object

조회수 973회
#include<stdio.h>

int main()
{
    const char *a[2]={"string"};    # 12
    scanf("%s", a[1]);              # 13
    printf("%s", a[1]);             # 14
}
main.c:13:5: warning writing into constant object (argument 2) [-Wformat=]
hi
(null)

...Program finished with exit code 0

사진처럼 문자열 2번째에 입력했는 null이라고 나옵니다.. 어떻게 입력하나요..?

  • memory allocation 사용하세요. dbwodlf3 2020.6.21 11:33

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)