#include <stdio.h>
#include <stdlib.h>
typedef struct student
{
int data;
struct student * next;
}Lnode, * Linklist;
Linklist create( int n )
{
int i = 0;
int x;
Linklist head = (Linklist) malloc( sizeof( Lnode ));
head->data = 0;
head->next = NULL;
printf("請輸入%d個結點的data值:\n", n);
while( i < n )
{
Linklist s = (Linklist) malloc( sizeof( Lnode ));
scanf("%d", &x );
s->data = x;
s->next = head->next;
head->next = s;
i++;
}
return head; //回傳頭結點
}
int main()
{
int n;
printf("請輸入鏈表結點數n:");
scanf("%d", &n);
Linklist head = NULL;
head = create( n );
Linklist p = head->next;
while(p)
{
printf("%d", p->data );
p = p->next;
}
return 0;
}
以上就是我的代碼,編譯時提示Linklist非法“” error C2275: 'Linklist' : illegal use of this type as an expression
G:\C語言練習\34lianbiao.c(8) : see declaration of 'Linklist'“”
uj5u.com熱心網友回復:
我編譯時未產生錯誤VS2017
uj5u.com熱心網友回復:
所以可截屏否?uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
error C2275: ‘XXX’ : illegal use of this type as an expression 報錯的解決方法:當你命名你的源檔案*.c時,MSVC假定它正在編譯C,這意味著C89。所有塊本地變數都需要在塊的開頭宣告:在代碼塊的開始部分宣告/初始化所有區域變數(緊接在大括號之后{);將源檔案重命名為*.cpp或等效并編譯為C ++。供參考(https://stackoverflow.com/questions/9549521/compiler-error-c2275):int main()
{
Linklist head = NULL;//把這句定義移到第一句,試試。
int n;
printf("請輸入鏈表結點數n:");
scanf("%d", &n);
head = create( n );
Linklist p = head->next;
while(p)
{
printf("%d", p->data );
p = p->next;
}
return 0;
}
uj5u.com熱心網友回復:
漏了p了,補充修改下:int main()
{
Linklist p=NULL, head = NULL;//把這句定義移到第一句,試試。
int n;
printf("請輸入鏈表結點數n:");
scanf("%d", &n);
head = create( n );
p = head->next;
while(p)
{
printf("%d", p->data );
p = p->next;
}
return 0;
}
uj5u.com熱心網友回復:
同意4樓結論。VC6是98年的,應該正兒八經的C89。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/268079.html
標籤:新手樂園
上一篇:列舉與模擬內容總結
下一篇:~a|a為什么是-1
