|
ㅋㅋㅋ 네.. 잘못된 인쇄 겠지요. 아님 저자의 오타이거나..
strncpy(qwords[i], temp, TARGSIZE = 1);
qwords[i][TARGSIZE = 1] = '\0';
여기서 TARGSIZE = 1 가 아니라 TARGSIZE + 1 이겠지요.. = 아니고 +
널 문자를 제일 마지막 에 넣어주는 것이지만..
하면 안되는 방법이지요.
char Str[10]; 로 선언하면 10개의 요소 0..9까지 사용합니다.
Str[10]은 사실은 쓰면 안되는 거죠. 써도.. 별일이야 없겠지만.. ㅋㅋ
열공하세요..
카니팡...... 님이 쓰신 글 :
: c언어 기초플러스라는 책으로 공부중입니다.
:
: 툴은 볼랜드 c++2006 터보익스플로러구요.
:
: 근데 밑에 있는 소스가 안됩니다.
:
: 책하고 비교해보니 오타도 없는거 같은데 왜 안되는지 궁금합니다.
:
: //strncpy()예제
: #include <stdio.h>
: #include <string.h>
: #define SIZE 40
: #define TARGSIZE 7
: #define LIM 5
:
: int main(void)
: {
: char qwords[LIM][TARGSIZE];
: char temp[SIZE];
: int i = 0;
: printf("Enter %d words beginning with q:\n", LIM);
: while (i < LIM && gets(temp))
: {
: if (temp[0] != 'q')
: {
: printf("%s doesn't begin with q!\n", temp);
: }
: else
: {
: strncpy(qwords[i], temp, TARGSIZE = 1);
: qwords[i][TARGSIZE = 1] = '\0';
: i++;
: }
: }
: puts("Here are the words accepted:");
: for(i = 0; i < LIM; i++)
: {
: puts(qwords[i]);
: }
: return 0;
: }
|