0
所以即時通訊使用二進制文件來保存有關某些節點(系統內部的東西)狀態的信息。關鍵是這個二進制文件只是很多的1和0,想法是讀取文件並將其加載到結構中。 這是該結構的定義:C - 從文件加載鏈接列表
typedef struct t_bitmap{
int estado;
struct t_bitmap* siguiente;
}t_bitmap;
而這是應該加載它的代碼:
t_bitmap leerBitmap(char* unPath){
t_bitmap bitmap;
FILE *fp = fopen (unPath, "rb");
int i=0;
fseek(fp, 0, SEEK_END);
int tamanio = sizeof(char) * ftell(fp);
fseek(fp, 0, SEEK_SET);
char* bytes = malloc(tamanio);
fread(bytes, tamanio, 1, fp);
fclose (fp);
while(i<tamanio){
bitmap.estado = bytes[i];
bitmap = bitmap.siguiente; //This fails
i++;
};
free(bytes);
return bitmap;
};
EDIT 1
的錯誤是: 不相容從類型'struct t_bitmap *'分配類型't_bitmap'時的類型
好。你在這裏是因爲...? – zerkms
指針'struct'成員僅在上下文中相關。你無法從文件中有效地讀取它們 - 如果你得到了那麼多。 –
@zerkms我不知道如何穿過位圖給每個estado值。我指出哪一行失敗。 – Marco