D
duncanblacksmithmath
Could someone help me try to fix these errors on this code. Thanks!!
Information:
information:
A function to access an element of a list by its index called
access_i(LL, i). It traverses
the list LL and returns the address of the i-th element in LL, if there
is one. Otherwise it
returns null.
A function to access an element of a list by value called access v(LL,
V). This function
traverses the list LL searching for an element with the value V. The
address of the rst such
element, if found, is returned. Otherwise a null pointer is returned.
errors:
program1.c: In function `access_num':
program1.c:71: warning: comparison between pointer and integer
program1.c: In function `access_val':
program1.c:79: warning: passing arg 1 of `strcmp' from incompatible
pointer type
code:
#include <stdio.h>
#include <stdlib.h>
#include "scan.h"
struct Val
{
char type;
int length;
char value[256];
} Values[1000];
struct Obj
{
struct Obj *p_link;
struct Val *p_value;
struct Obj *n_link;
} Objects[1000], *IdList, *NrList, *SpList, *UnList ;
int i = 0, j = 0; /* 0 <= i,j <= 999, objects and vcalues indices */
struct Obj *List (struct Obj *h, struct Obj *t)
{
h->p_link = NULL;
h->n_link = t;
h->p_value = NULL;
t->p_link = h;
t->n_link = NULL;
t->p_value = NULL;
return h;
}
int Append(struct Obj *L, struct Val *item)
{
struct Obj *Temp = L->n_link;
while (Temp->n_link != NULL)
Temp = Temp->n_link;
if ((i <= 999))
{
(Temp->p_link)->n_link = &Objects;
Objects.n_link = Temp;
Objects.p_link = Temp->p_link;
Temp->p_link = &Objects;
Objects.p_value = &Values[j];
i = i+1;
return 1;
}
else return 0;
}
struct Obj *access_i(struct Obj *l, int num_wanted)
{
int atPoint=0;
struct Obj *current=l;
while(atPoint != num_wanted)
{
atPoint++;
if(current->n_link == NULL) return NULL;
current=current->n_link;
}
return current;
}
struct Obj *access_num(struct Obj *l, int value)
{
struct Obj* current=l;
while(current != NULL && current->p_value != value)
current=current->n_link;
return current;
}
struct Obj *access_val(struct Obj *l, char *value)
{
struct Obj* current=l;
while(current != NULL && !strcmp(current->p_value, value))
current=current->n_link;
return current;
}
int PrintLists(struct Obj *list)
{
struct Obj *Temp = list->n_link;
printf("Type\tLength\tValue\n");
while (Temp->n_link != NULL)
{
printf("%c\t%d\t%s\n", Temp->p_value->type,
Temp->p_value->length, Temp->p_value->value);
Temp = Temp->n_link;
}
}
int main (int argc, char *argv[])
{
extern TKN get_token(FILE *);
TKN Token;
FILE *Input;
int Done = 0;
IdList = List(&Objects[0], &Objects[1]);
NrList = List(&Objects[2], &Objects[3]);
SpList = List(&Objects[4], &Objects[5]);
UnList = List(&Objects[6], &Objects[7]);
i = 8; j = 0;
Input = fopen(argv[1], "r");
while (!Done)
{
Token = get_token( Input );
switch (Token.Code)
{
case 'I':
{
/* process identifier */
printf("Symbol: Identifier %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'I';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (IdList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'N':
{
/* process integer number */
printf("Symbol: Integer number %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'N';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (NrList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'F':
{
/* process real number */
printf("Symbol: Real number %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'F';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (NrList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'W':
{
printf("White symbol received\n");
break;
}
case 'U':
{
if (Token.String[0] == 'Z')
Done = 1;
else
printf("Unprintable character
discovered\n");
break;
}
case 'O':
{
printf("Symbol: Separator %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'S';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (SpList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'E':
{
printf("Error condition: %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'E';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (UnList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
}
} /* end while */
printf("List of NAMES\n");
PrintLists(IdList);
printf("List of NUMBERS\n");
PrintLists(NrList);
printf("List of SEPARATORS\n");
PrintLists(SpList);
printf("List of UNKNOWNS\n");
PrintLists(UnList);
return 0;
}
Information:
information:
A function to access an element of a list by its index called
access_i(LL, i). It traverses
the list LL and returns the address of the i-th element in LL, if there
is one. Otherwise it
returns null.
A function to access an element of a list by value called access v(LL,
V). This function
traverses the list LL searching for an element with the value V. The
address of the rst such
element, if found, is returned. Otherwise a null pointer is returned.
errors:
program1.c: In function `access_num':
program1.c:71: warning: comparison between pointer and integer
program1.c: In function `access_val':
program1.c:79: warning: passing arg 1 of `strcmp' from incompatible
pointer type
code:
#include <stdio.h>
#include <stdlib.h>
#include "scan.h"
struct Val
{
char type;
int length;
char value[256];
} Values[1000];
struct Obj
{
struct Obj *p_link;
struct Val *p_value;
struct Obj *n_link;
} Objects[1000], *IdList, *NrList, *SpList, *UnList ;
int i = 0, j = 0; /* 0 <= i,j <= 999, objects and vcalues indices */
struct Obj *List (struct Obj *h, struct Obj *t)
{
h->p_link = NULL;
h->n_link = t;
h->p_value = NULL;
t->p_link = h;
t->n_link = NULL;
t->p_value = NULL;
return h;
}
int Append(struct Obj *L, struct Val *item)
{
struct Obj *Temp = L->n_link;
while (Temp->n_link != NULL)
Temp = Temp->n_link;
if ((i <= 999))
{
(Temp->p_link)->n_link = &Objects;
Objects.n_link = Temp;
Objects.p_link = Temp->p_link;
Temp->p_link = &Objects;
Objects.p_value = &Values[j];
i = i+1;
return 1;
}
else return 0;
}
struct Obj *access_i(struct Obj *l, int num_wanted)
{
int atPoint=0;
struct Obj *current=l;
while(atPoint != num_wanted)
{
atPoint++;
if(current->n_link == NULL) return NULL;
current=current->n_link;
}
return current;
}
struct Obj *access_num(struct Obj *l, int value)
{
struct Obj* current=l;
while(current != NULL && current->p_value != value)
current=current->n_link;
return current;
}
struct Obj *access_val(struct Obj *l, char *value)
{
struct Obj* current=l;
while(current != NULL && !strcmp(current->p_value, value))
current=current->n_link;
return current;
}
int PrintLists(struct Obj *list)
{
struct Obj *Temp = list->n_link;
printf("Type\tLength\tValue\n");
while (Temp->n_link != NULL)
{
printf("%c\t%d\t%s\n", Temp->p_value->type,
Temp->p_value->length, Temp->p_value->value);
Temp = Temp->n_link;
}
}
int main (int argc, char *argv[])
{
extern TKN get_token(FILE *);
TKN Token;
FILE *Input;
int Done = 0;
IdList = List(&Objects[0], &Objects[1]);
NrList = List(&Objects[2], &Objects[3]);
SpList = List(&Objects[4], &Objects[5]);
UnList = List(&Objects[6], &Objects[7]);
i = 8; j = 0;
Input = fopen(argv[1], "r");
while (!Done)
{
Token = get_token( Input );
switch (Token.Code)
{
case 'I':
{
/* process identifier */
printf("Symbol: Identifier %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'I';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (IdList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'N':
{
/* process integer number */
printf("Symbol: Integer number %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'N';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (NrList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'F':
{
/* process real number */
printf("Symbol: Real number %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'F';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (NrList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'W':
{
printf("White symbol received\n");
break;
}
case 'U':
{
if (Token.String[0] == 'Z')
Done = 1;
else
printf("Unprintable character
discovered\n");
break;
}
case 'O':
{
printf("Symbol: Separator %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'S';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (SpList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
case 'E':
{
printf("Error condition: %s\n",
Token.String);
if (j < 999)
{
j = j+1;
Values[j].type = 'E';
Values[j].length = strlen(Token.String);
strcpy(Values[j].value, Token.String);
Append (UnList, &Values[j]);
}
else
printf("No plave available for this
value\n");
break;
}
}
} /* end while */
printf("List of NAMES\n");
PrintLists(IdList);
printf("List of NUMBERS\n");
PrintLists(NrList);
printf("List of SEPARATORS\n");
PrintLists(SpList);
printf("List of UNKNOWNS\n");
PrintLists(UnList);
return 0;
}