Hello, I have the following code. Compile in my PC is OK ,and almost can print the right answer. But upload have many errors. I don't know why. Please.
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define knext *n[k].next
struct head
{
int a,last,*next;
};
struct num
{
int a,*next,line;
};
void upout(head h[],num n[],int k)
{
int *pot;
if(n[knext].next!=NULL) upout(h,n,knext);
if(h[knext].last==-1) h[knext].next=&n[knext].a;
else n[h[knext].last].next=&n[knext].a;
h[n[k].line].last=k;
h[knext].last=knext;
n[knext].line=knext;
n[k].next=NULL;
}
void move(head h[],num n[],int a,int b)
{
int *pot;
pot=h[n[a].line].next;
if(*pot==a)
{
h[n[a].line].last=-1;
h[n[a].line].next=NULL;
}
else
{
while(*pot!=a)
{
h[n[a].line].last=*pot;
pot=n[*pot].next;
}
n[h[n[a].line].last].next=NULL;
}
n[h[n[b].line].last].next=&n[a].a;
pot=n[h[n[b].line].last].next;
while(pot!=NULL)
{
n[*pot].line=n[b].line;
h[n[b].line].last=*pot;
pot=n[*pot].next;
}
}
void prt(head h[],num n[],int number)
{
int*pot;
for(int i=0;i<number;i++)
{
printf("%d(%d):",h[i].a,h[i].last);
pot=h[i].next;
while(pot!=NULL)
{
printf(" %d(%d)",*pot,n[*pot].line);
pot=n[*pot].next;
}
printf("\n");
}
}
int main()
{
int number,i,a,b;
char input[20],fi[10],se[10];
scanf("%d\n",&number);
struct head *h=(head*)malloc(number*sizeof(head));
struct num *n=(num*)malloc(number*sizeof(num));
for(i=0;i<number;i++)
{
h[i].a=i;
h[i].last=i;
h[i].next=&(n[i].a);
}
for(i=0;i<number;i++)
{
n[i].a=i;
n[i].next=NULL;
n[i].line=i;
}
while(true)
{
gets(input);
if(!strcmp(input,"quit")) break;
if(!strcmp(input,"print")) prt(h,n,number);
sscanf(input,"%s %d %s %d",fi,&a,se,&b);
if(n[a].line==n[b].line) continue;
if(!strcmp(fi,"move"))
{
if(n[a].next!=NULL) upout(h,n,a);
if(!strcmp(se,"onto"))
if(n[b].next!=NULL) upout(h,n,b);
move(h,n,a,b);
}
else if(!strcmp(fi,"pile"))
{
if(!strcmp(se,"onto"))
if(n[b].next!=NULL) upout(h,n,b);
move(h,n,a,b);
}
}
prt(h,n,number);
return 0;
}
error messages
05336590_24.c:17: parse error before `h'
05336590_24.c: In function `upout':
05336590_24.c:20: `n' undeclared (first use in this function)
05336590_24.c:20: (Each undeclared identifier is reported only once
05336590_24.c:20: for each function it appears in.)
05336590_24.c:20: `k' undeclared (first use in this function)
05336590_24.c:20: `h' undeclared (first use in this function)
05336590_24.c: At top level:
05336590_24.c:31: parse error before `h'
05336590_24.c: In function `move':
05336590_24.c:34: `h' undeclared (first use in this function)
05336590_24.c:34: `n' undeclared (first use in this function)
05336590_24.c:34: `a' undeclared (first use in this function)
05336590_24.c:49: `b' undeclared (first use in this function)
05336590_24.c: At top level:
05336590_24.c:60: parse error before `h'
05336590_24.c: In function `prt':
05336590_24.c:63: parse error before `int'
05336590_24.c:63: `i' undeclared (first use in this function)
05336590_24.c:63: `number' undeclared (first use in this function)
05336590_24.c:63: parse error before `)'
05336590_24.c:66: `h' undeclared (first use in this function)
05336590_24.c:69: `n' undeclared (first use in this function)
05336590_24.c: At top level:
05336590_24.c:74: parse error before `}'
05336590_24.c: In function `main':
05336590_24.c:83: parse error before `struct'
05336590_24.c:87: `h' undeclared (first use in this function)
05336590_24.c:89: `n' undeclared (first use in this function)
05336590_24.c:97: `true' undeclared (first use in this function)