강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

cjkoo96님의 프로필 이미지
cjkoo96

작성한 질문수

홍정모의 따라하며 배우는 C언어

11.1 문자열을 정의하는 방법들

질문드립니다.

작성

·

395

0

char words[MAXLENGTH] = "A string in an array";

const char* pt1 = "A pointer to a string."; // point the first address of sentence

puts("Puts() adds a newline at the end: "); // puts() add \n at the end

puts(MESSAGE);

puts(words); // char words[21] removes this warning -> Total 81 sizes but, only 21 sizes are initialized

puts(pt1);

words[3] = 'p'; // OK

puts(words);

//pt1[8] = 'A'; // Runtime Error 건들이면 안되는 부분임 

puts(pt1);

char greeting[50] = "Hello, and" " How are" " you"

" today!"; //아래 코드와 같음.

//char greeting[50] = "Hello, and How are you today!"; 

puts(greeting);

printf("%s, %p, %c\n", "We", "are", *"excellent programmers");

char cookies[1] = { 'A', }; //char cookies[1] = {'A'}; 도 같은 결과가 나옴

puts(cookies);

위 코드를 실행해보니 

이렇게 출력되더라고요 

그리고 puts(cookies); 에 초록색 밑줄로 String 'cookies' might not be zero-terminated. 라고 나옵니다.

어디서 문제가 발생한건지, Hello, and How are you today! 는 왜 한번 더 출력된건지 궁금합니다.

답변 2

0

cjkoo96님의 프로필 이미지
cjkoo96
질문자

문자열이 아닌 문자의 뒤에도 널캐릭터가 들어가나요?

0

안녕하세요?
안타깝게도 지금은 답변드리기 힘들 것 같군요.
제가 바로 실행할 수 있도록 코드를 올려주시는 편이 좋습니다.
저는 한단계 한단계 천천히 살펴보시는 것을 권장해드리고 싶은데, 고민해보시고 다시 모르시겠다면 전체 코드를 올려주세요.

cjkoo96님의 프로필 이미지
cjkoo96

작성한 질문수

질문하기