문자열을 표준 입력에서 버퍼로 복사하는 데 문제가 있습니다. 문자열의 크기는 12 문자로 HS1234-0.txt는 나중에 사용하기 위해 다음 코드를 사용합니다.채팅을 버퍼에 복사하는 중 오류가 발생했습니다.
그것을 액세스하려고 여기서 수행while(1) {
sem_wait(&escsem);
pthread_mutex_lock(&esctrin);
char filename[12];
read(STDIN_FILENO,filename,12); //this is where I read from the stdin
lseek(STDIN_FILENO,13,SEEK_SET);
buffer[bufferpos]=filename; //this is where I try to copy
bufferpos=(bufferpos+1) % BUFFER_SIZE;
conta++;
pthread_mutex_unlock(&esctrin);
sem_post(&lesem);
}
및이지만, 그 버퍼가 [bufferpos] 널 말하는 유지하고 file_to_open 각 조각은 서로 다른 스레드와 버퍼에서 사용되고 또한
char* file_to_open;
while(1){
sem_wait(&lesem);
pthread_mutex_lock(&lertrin);
file_to_open=buffer[bufferpos];//this is where i try to copy the string
printf("buffer %s file %s\n",buffer[bufferpos],file_to_open);//and here it return null on both
bufferpos=(bufferpos+1) % BUFFER_SIZE;
conta++;
pthread_mutex_unlock(&lertrin);
sem_post(&escsem);
}
널
012로 선언다음 문제는 filename
가 특정 루프 내에서만 유효한 로컬 변수입니다 당신이 문자 포인터의 배열로 buffer
를 사용하려면 어떻게 든 사전
char 버퍼 [BUFFER_SIZE]; – DRC
'buffer [bufferpos] = filename; // 여기가 복사하려고합니다. 그것은 아무것도 복사하지 않습니다. 그냥'buffer [bufferpos]'를 포인터 인'filename'과 동일하게 설정합니다. –
나는 buffer가'char *'타입의 배열이기 때문에 그 사실을 알고 있다고 생각했다. – Jite