[英]dereferencing pointer to incomplete type of a struct
I have a struct and im trying to store an offset into my mp3length and data read from a file into my data.我有一个结构,我试图将偏移量存储到我的 mp3length 中,并将从文件中读取的数据存储到我的数据中。 However when i assign my offset to my dynamic array, it tells me "dereferencing pointer to incomplete type 'struct mp3data_t'. Is anyone able to explain this error?
但是,当我将偏移量分配给动态数组时,它告诉我“取消引用指向不完整类型'struct mp3data_t'的指针。有人能解释这个错误吗?
My error is on the line mp3[num]->mp3length = mp3filesize;
我的错误在于
mp3[num]->mp3length = mp3filesize;
typedef struct mp3 {
char *data;
int mp3length;
} mp3data_t;
void listFilesRecursively(char *basePath)
{
char path[1000];
int file_length;
DIR *current = opendir(basePath);
// Unable to open directory stream
if (!current)
return;
while ((entry = readdir(current)) != NULL)
{
if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
{
printf("%s\n", entry->d_name);
// Construct new path from our base path
strcpy(path, basePath);
strcat(path, "/");
strcat(path, entry->d_name);
printf("Path: %s\n", path);
file_length = strlen(entry->d_name);
if(entry->d_name[file_length - 1] == 51 &&
entry->d_name[file_length - 2] == 112 &&
entry->d_name[file_length - 3] == 109)
{
printf("------------------\n");
printf("Writing %s to file\n", entry->d_name);
printf("------------------\n");
if(length < (num + 1))
{
length = num + 1;
}
FILE *mp3file;
if ((mp3file = fopen(path, "rb")) != NULL)
{
//SET POINTER TO THE END OF THE FILE TO GET THE SIZE
fseek(mp3file, 0, SEEK_END);
int mp3filesize = ftell(mp3file);
// SET POINTER BACK TO THE BEGINNING
fseek(mp3file, 0, SEEK_SET);
mp3 = realloc(mp3, sizeof(mp3data_t*) * length);
mp3[num] = malloc(mp3filesize + 1);
mp3[num]->mp3length = mp3filesize;
int ret = fread(mp3[num]->data, sizeof(char), mp3filesize, mp3file);
if(ret == 0)
{
printf("nothing read\n");
}
fclose(mp3file);
}
else
{
printf("ERROR READING FILE\n");
}
// THEN USE FSEEK
//strcpy(data[num], entry->d_name);
num++;
}
listFilesRecursively(path);
}
}
closedir(current);
return;
}
What you declared here is struct mp3
and mp3data_t
.您在这里声明的是
struct mp3
和mp3data_t
。 struct mp3data_t
is not declared (or at least not posted here). struct mp3data_t
未声明(或至少未在此处发布)。
It looks like you should use either one of struct mp3
or mp3data_t
.看起来您应该使用
struct mp3
或mp3data_t
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.