вот как я скомпилировал: gcc -o adt adt.c
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef struct Item* link;
struct Item {
char c;
int i;
link next;
link previous;
};
static link curr;
void LISTinit (); /* initialise the list */
int LISTempty (); /* is the list empty? */
int LISTmove (int n); /* move current position */
Item LISTcurrent (); /* return element at current position */
void LISTbefore (Item newItem); /* insert element before current */
void LISTafter (Item newItem); /* insert element after current */
Item LISTdelete (); /* delete current element */
void LISTinit (){
curr = NULL;
}
link newNode (int a, char b) {
link ls;
ls = malloc (sizeof (*ls));
ls->i = a;
ls->c = b;
ls->next = NULL;
ls->previous = NULL;
return ls;
}
int LISTempty (){
if (curr == NULL){
return TRUE;
}
return FALSE;
}
int LISTmove (int n);{
int flag = 0;
if (LISTempty() == TRUE){
printf("list is empty\n");
flag = TRUE;
}
else {
if ( n < 0 ){
if( curr->previous != NULL){
curr = curr->previous;
flag = LISTmove (n+1);
}
else {
flag = TRUE;
}
}
else if( n > 0){
if( curr->next != NULL){
curr = curr->next;
flag = LISTmove (n-1);
}
else{
flag = TRUE;
}
}else{
if(curr->previous != NULL || curr->next != NULL )flag = TRUE;
else flag = FALSE;
}
}
return flag;
}
Item LISTcurrent (){
return *curr;
}
void LISTbefore (Item newItem){
newItem->previous = curr->previous;
curr->previous = newItem;
newItem->next = curr;
curr = &newItem;
}
void LISTafter (Item newItem){
newItem->next = curr->next;
curr->next = newItem;
newItem->previous = curr;
curr = &newItem;
}
Item LISTdelete (){
if( curr->next == NULL){
curr->previous->next = NULL;
curr = curr->previous;
} else if( curr->previous == NULL){
curr->next->previous = NULL;
curr = curr->next;
} else {
curr->previous->next = curr->next;
curr->next->previous = curr->previous;
curr = curr->previous;
}
return *curr;
}
получил эти ошибки
adt.c:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'LISTcurrent'
adt.c:20: error: expected ')' before 'newItem'
adt.c:21: error: expected ')' before 'newItem'
adt.c:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'LISTdelete'
adt.c:51: error: expected identifier or '(' before '{' token
adt.c:85: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'LISTcurrent'
adt.c:89: error: expected ')' before 'newItem'
adt.c:97: error: expected ')' before 'newItem'
adt.c:105: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'LISTdelete'
Спасибо!
теперь есть другая проблема
#include <stdlib.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef struct item Item;
typedef Item* link;
struct item {
char c;
int i;
link next;
link previous;
};
static link curr;
void LISTinit (); /* initialise the list */
int LISTempty (); /* is the list empty? */
int LISTmove (int n); /* move current position */
Item LISTcurrent (); /* return element at current position */
void LISTbefore (Item newItem); /* insert element before current */
void LISTafter (Item newItem); /* insert element after current */
Item LISTdelete (); /* delete current element */
void LISTinit (){
curr = NULL;
}
link newNode (int a, char b) {
link ls;
ls = malloc (sizeof (*ls));
ls->i = a;
ls->c = b;
ls->next = NULL;
ls->previous = NULL;
return ls;
}
int LISTempty (){
if (curr == NULL){
return TRUE;
}
return FALSE;
}
int LISTmove (int n){
int flag = 0;
if (LISTempty() == TRUE){
printf("list is empty\n");
flag = TRUE;
}
else {
if ( n < 0 ){
if( curr->previous != NULL){
curr = curr->previous;
flag = LISTmove (n+1);
}
else {
flag = TRUE;
}
}
else if( n > 0){
if( curr->next != NULL){
curr = curr->next;
flag = LISTmove (n-1);
}
else{
flag = TRUE;
}
}else{
if(curr->previous != NULL || curr->next != NULL )flag = TRUE;
else flag = FALSE;
}
}
return flag;
}
Item LISTcurrent (){
return *curr;
}
void LISTbefore (Item newItem){
newItem->previous = curr->previous;
curr->previous = newItem;
newItem->next = curr;
curr = &newItem;
}
void LISTafter (Item newItem){
newItem->next = curr->next;
curr->next = newItem;
newItem->previous = curr;
curr = &newItem;
}
Item LISTdelete (){
if( curr->next == NULL){
curr->previous->next = NULL;
curr = curr->previous;
} else if( curr->previous == NULL){
curr->next->previous = NULL;
curr = curr->next;
} else {
curr->previous->next = curr->next;
curr->next->previous = curr->previous;
curr = curr->previous;
}
return *curr;
}
ошибка
gcc -o adt adt.c
adt.c: In function 'LISTbefore':
adt.c:93: error: invalid type argument of '->' (have 'Item')
adt.c:95: error: invalid type argument of '->' (have 'Item')
adt.c: In function 'LISTafter':
adt.c:101: error: invalid type argument of '->' (have 'Item')
adt.c:103: error: invalid type argument of '->' (have 'Item')