繁体   English   中英

取消引用指向结构的不完整类型的指针

[英]dereferencing pointer to incomplete type of a struct

我有一个结构,我试图将偏移量存储到我的 mp3length 中,并将从文件中读取的数据存储到我的数据中。 但是,当我将偏移量分配给动态数组时,它告诉我“取消引用指向不完整类型'struct mp3data_t'的指针。有人能解释这个错误吗?

我的错误在于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;
}

您在这里声明的是struct mp3mp3data_t struct mp3data_t未声明(或至少未在此处发布)。

看起来您应该使用struct mp3mp3data_t

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM