我在C中有一個單獨鏈接列表程序。當我在TC++上編譯它時,它只有2個關於某些聲明(它的罰款)的錯誤。但是當我使用GCC在Ubuntu中編譯它時,它有太多的錯誤。我爲該結構的成員創建了一個名爲NODE的自定義數據類型,但GCC不接受它。正如我已經使用typedef,有一個錯誤說 -C編寫結構的規則是否因Turbo C++編譯器和GCC而異?
expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
任何規則我錯過了?請幫幫我!
這是代碼:
#include<stdio.h>
typdef struct node
{
int data;
NODE *next;
}NODE;
//Creation Of the Nodes with NULL pointers
NODE* createnewnode()
{
NODE* nn;
nn=(NODE*)malloc(sizeof(NODE));
if(nn==NULL)
{
printf("Insufficient Memory");
exit(0);
}
printf("Enter data");
scanf("%d",&nn->data);
nn->next=NULL;
return(nn);
}
// Creation Of the Links
NODE* createlinkedlist(NODE *hn, int n)
{
NODE *cn, *nn;
for(i=0;i<n;i++);
{
nn=createnewnode();
if(hn==NULL)
{
hn=nn;
}
else
{
cn->next==nn;
}
cn=nn;
return(hn);
}
//Display of The Data
void display(NODE *hn)
{
NODE *cn;
for(cn=hn;cn!=NULL;cn=cn->next)
{
printf("\t %d, "cn->data);
}
}
//Linear Searching
void search(NODE *hn, int n)
{
NODE *cn;
int i, x;
printf("Enter the data to be found");
scanf("%d",&x);
i=0;
while(i<n)
{
if(x==cn->data)
{
printf("Data found at %d",i+1);
break;
}
cn=cn->next;
i=i++;
}
}
void main()
{
int n;
NODE* hn=NULL;
printf("Enter the number of nodes to be created");
scanf("%d",&n);
createlinkedlist(hn,n);
display(hn);
}
拼寫錯誤'typedef'。 – chris 2012-08-15 08:37:13
如果編譯器給出任何形式的錯誤,代碼就不好。不同的編譯器在第一個之後可能會也可能不會顯示相關的錯誤,但不要指望它。第二個錯誤可能與第一個錯誤有關。 – Lundin 2012-08-15 09:41:39