-1
我正在嘗試編寫程序來讀取它所在程序所在的文件夾的相關信息。我在其他在線源中檢查了一倍,並且它看起來像我正在使用與其他正確的解決方案相同的模式(見下文)。從不兼容的指針類型和解引用指針到不完整類型的指派<dirent.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
void append(char* path, char* cur)
{
strcat("/",cur);
strcat(cur,path);
}
void addDot(char* dot)
{
int len = strlen(dot);
dot[len] = '.';
}
int main()
{
struct stat st;
int stDevCur = st.st_ino;
int stDevNew = 0;
int inodeCur = st.st_dev;
int inodeNew = 0;
char* path = "";
char* new = "";
char* cur = "_";
char* dot = ".";
DIR* dir;
struct dirnet* file = NULL;
if((dir = opendir(dot)) == NULL)
{
perror(NULL);
exit(EXIT_FAILURE);
}
while(strcmp(cur,new) != 0)
{
if((file = readdir(dir)) == NULL)
{
perror(NULL);
exit(EXIT_FAILURE);
}
while(file != NULL)
{
inodeNew = st.st_ino;
stDevNew = st.st_dev;
if(inodeNew == inodeCur && stDevNew == stDevCur)
{
cur = file->d_name;
append(path, cur);
break;
}
}
fprintf(stderr,"%s\n",path);
}
return 0;
}
提供了以下錯誤
main.c: In function ‘main’:
main.c:42:16: error: assignment from incompatible pointer type [-Werror]
if((file = readdir(dir)) == NULL)
^
main.c:53:23: error: dereferencing pointer to incomplete type
cur = file->d_name;
^
cc1: all warnings being treated as errors
make: *** [main.o] Error 1
我一直在尋找這一點,因爲昨晚已在它們具有類似的問題在計算器