당신이 2 차원 배열의 요소로 라인을 읽어가는 것 같다.는 C 표준에서
(7.21.7.2를 fgets 함수)
3 The fgets function returns s if successful. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.
따라서 올바른 루프는
size_t i = 0;
while(i < SIZE && fgets(names[i], LENGTH, stdin) != NULL)
{
//...
++i;
}
처럼 보일 수 있습니다 또는 당신은 빈 줄이 다음 encounterd 때 라인 읽기를 중단하려는 경우 당신은
size_t i = 0;
while(i < SIZE && fgets(names[i], LENGTH, stdin) != NULL && names[i][0] != '\n')
{
//...
++i;
}
오류 메시지를 쓸 수 있습니다 컴파일러에서 발행 한 내용은 다음과 같습니다.
Passing argument 1 of 'fgets' from incompatible pointer type.
첫 번째 인수로서 사용이 함수 호출
fgets(names, LENGTH, stdin)
식 names
210
는 char (*)[LENGTH]
입력 갖지만 함수 타입 char *
의 인수를 기대한다.
"Comparison between pointer and zero character constant. Did you mean to dereference the pointer?
이 메시지는 함수 포인터에 의해 반환 된이 널 포인터와 비교하거나 문자 '\0'
으로 반환 된 포인터에 의해 캐릭터가 지적 비교 거라고 여부를 컴파일러가 결론을 내릴 수 없음을 의미합니다.
좋은 C 책이 필요합니다. –