簡體   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