I have a struct and im trying to store an offset into my mp3length and data read from a file into my data. 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?
My error is on the line 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 mp3data_t
is not declared (or at least not posted here).
It looks like you should use either one of struct mp3
or mp3data_t
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.