プログラム初心者です
私は今学校の課題でリスト構造のプログラムを作成しています
仕様は以下のとおりです
・テキストファイルより1行(255字以内)受け取りリスト構造に追加する
・リスト構造は昇順に追加する( 順序はstrcmp()仕様による )
・テキストファイルを表示する
・リスト構造追加後の結果を表示する
プログラム自体はできあがっているのですが
エラーが取れません
作成したプログラムは以下の通りです
#include <stdio.h>
#include <stdlib.h>
typedef struct list{
struct list *next;
char str[256];
}ELEMENT;
int main (void){
FILE *fp;
struct ELEMENT *root = NULL;
struct ELEMENT *elem,*pos,*work;
int i;
if(fp = fopen("strings.dat","r") == NULL){
printf("ファイルを開けません\n");
exit(1);
}
while(!feof(fp)){
if(elem = (ELEMENT*) malloc(sizeof(ELEMENT)) == NULL){
printf("メモリ割り当てエラー\n");
exit(1);
}
fgets(elem->str , 255 , fp); // 1行取得
printf("%s" , elem->str);
if(root == NULL){ // 空だった場合
elem->next = NULL;
root = elem;
}else{
pos = root;
while(pos != NULL){
i = strcmp(elem->str , pos->str);
if(i < 0) break;
work = pos;
pos = pos->next;
}
if(pos == NULL){ // 最後尾に追加
elem->next = NULL;
pos->next = elem;
}else if(pos == root){ // 先頭に追加
elem->next = pos;
root = elem;
}else{ // 間に追加
elem->next = pos;
work->next = elem;
}
}
}
fclose(fp);
work = root;
while(work != NULL){
pos = work->next;
printf("%s",work->str);
free(work);
work = pos;
}
return 0;
}
使用しているコンパイラは独習Cに付属しているGNU C Compilerです
出るエラーは以下のものです
list.c: In function `main':
list.c:16: warning: assignment makes pointer from integer without a cast
list.c:22: warning: assignment makes pointer from integer without a cast
list.c:27: error: dereferencing pointer to incomplete type
list.c:28: error: dereferencing pointer to incomplete type
list.c:31: error: dereferencing pointer to incomplete type
list.c:37: error: dereferencing pointer to incomplete type
list.c:37: error: dereferencing pointer to incomplete type
list.c:42: error: dereferencing pointer to incomplete type
list.c:46: error: dereferencing pointer to incomplete type
list.c:47: error: dereferencing pointer to incomplete type
list.c:49: error: dereferencing pointer to incomplete type
list.c:52: error: dereferencing pointer to incomplete type
list.c:53: error: dereferencing pointer to incomplete type
list.c:62: error: dereferencing pointer to incomplete type
list.c:63: error: dereferencing pointer to incomplete type
このエラーの意味はなんなのでしょうか?
どうかご教授お願いいたします
