gcc 4.4.1읽기 기능을 사용하여 파일을 읽는 중
나는 읽기 기능을 사용하여 웨이브 파일을 읽습니다. 그러나, 그것은 읽기 기능을 얻을 때. 실행이 중단 된 것처럼 보입니다. 내가이 일을 잘못하고 있는지 궁금해합니다.
파일 크기 test-short.wave는 514K입니다.
내가 목표로 한 것은 한 번에 파일을 메모리 버퍼로 읽어들입니다. 현재 나는 이것을 테스트하고 있습니다. 어떤 제안에 대한
많은 감사,
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
char buff = malloc(10240);
int32_t fd = 0;
int32_t bytes_read = 0;
char *filename = "test-short.wav";
/* open wave file */
if((fd = (open(filename, O_RDWR)) == -1))
{
fprintf(stderr, "open [ %s ]\n", strerror(errno));
return 1;
}
printf("Opened file [ %s ]\n", filename);
printf("sizeof(buff) [ %d ]\n", sizeof(buff));
bytes_read = read(fd, buff, sizeof(buff));
printf("Bytes read [ %d ]\n", bytes_read);
return 0;
}
=== 편집 수정의 ===
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
char buff[10240] = {0};
int32_t fd = 0;
int32_t bytes_read = 0;
const char *filename = "test-short.wav";
fd = open(filename, O_RDWR);
if(fd == -1)
{
fprintf(stderr, "open [ %s ]\n", strerror(errno));
return 1;
}
printf("sizeof(buff) [ %d ]\n", sizeof(buff));
printf("strlen(buff) [ %d ]\n", strlen(buff));
bytes_read = read(fd, buff, sizeof(buff));
printf("Bytes read [ %d ]\n", bytes_read);
return 0;
}
기침 libsndfile 기침 –