I got the program in place , but only two errors preventing me from compiling it..
line 63:
left operand must be modifiable lvalue: op "="
line 66:
left operand must be modifiable lvalue: op "="
cc: acomp failed for ar2.c
Where did I go wrong? Please see attached
Please help me successfully complie...Thank you very much!!!!
CODE:
______________________________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SPELL_OKAY 0 /* success */
#define SPELL_FAILURE -1 /* general, unspecified failure */
#define SPELL_NOMEMORY 1 /* could not allocate more memory */
#define SPELL_NOTFOUND 2 /* could not find a file */
#define SPELL_TOOLONG 3 /* a word is too long */
#define SPELL_INCORRECT 4 /* a word is incorrect */
#define MAXLENGTH 64
#define EXTEND_SIZE 20
/*Function declarations*/
int max_word_len(void);
int add_word(char *word);
void forget_word(char *word);
void forget_all(void);
int read_dict(char *file);
int check_word(char *word);
int check_file(char *file, void (*badword)(char *));
int extend_dictionary ( void );
char *dup_string ( char *word );
int compare_fn ( const void *a, const void *b );
int binsearch( char *word, char *dict[], int n);
void swap(char *v[], int i, int j);
void quicksort(char *v[], int left, int right);
char *dictionary[] = {NULL};
int num_words = 0;
int max_words = 0;
int main ( )
{
int i;
add_word( "Now" );
add_word( "is" );
add_word( "the" );
add_word( "time" );
add_word( "for" );
add_word( "all" );
add_word( "good" );
for ( i = 0 ; i < num_words ; i++ ) {
printf( "Word %d is %s\n", i, dictionary );
}
return 0;
}
/* extends the dictionary in steps of 20 words */
int extend_dictionary (void)
{
char* temp[] = {NULL};
int new_size;
if ( num_words == max_words )
{
new_size = max_words + EXTEND_SIZE;
temp = (char *)realloc(dictionary, new_size * sizeof(char) );
if ( temp != NULL )
{
dictionary = temp;
max_words = new_size;
}
else
return SPELL_NOMEMORY;
}
return SPELL_OKAY;
}
/* make a copy of a string */
char *dup_string ( char *word )
{
char *temp = malloc( strlen(word) + 1 );
if ( temp != NULL )
{
strcpy( temp, word );
return temp;
}
else
return NULL;
}
int add_word ( char *word )
{ int iptr;
char *ptr;
if( strlen(word) > max_word_len() )
return SPELL_TOOLONG;
/*check if the word is in the dictionary*/
if (check_word(word) == SPELL_OKAY)
return SPELL_OKAY;
else
{ if ( (ptr = dup_string(word))== NULL )
return SPELL_NOMEMORY;
else if ( (iptr = extend_dictionary()) == SPELL_NOMEMORY )
return SPELL_NOMEMORY;
else
{
dictionary[num_words++] = dup_string( word );
quicksort( dictionary, 0, num_words-1);
return SPELL_OKAY;
}
}
}
int max_word_len(void)
{ return MAXLENGTH;
}
int check_word(char *word)
{
int i, len;
int bNumeric = 1;
int wordnum = 0;
/*check for length*/
len = strlen(word);
if ( len > max_word_len())
return SPELL_TOOLONG;
for (i=0; i<len; i++)
{
/*not a digit*/
if ( isdigit(word) == 0)
{
bNumeric = 0;
break;
}
}
if (bNumeric == 1)
return SPELL_OKAY;
else
{
wordnum = binsearch(word, dictionary, num_words);
if ( wordnum != -1)
return SPELL_OKAY;
else
return SPELL_INCORRECT;
}
}
int binsearch( char *word, char *dict[], int n)
{ int low, high, mid;
low=0;
high = n-1;
while(low <=high)
{ mid = (low + high)/2;
if ( compare_fn(word, dict[mid]) < 0)
high = mid -1;
else if ( compare_fn(word, dict[mid]) > 0 )
low=mid+1;
else
return mid;
}
return -1;
}
void quicksort(char *v[], int left, int right)
{ int i, last;
void swap (char*v[], int i, int j);
if (left >=right)
return ;
swap(v, left, (left+right)/2);
last = left;
for (i = left+1; i<=right; i++)
if ( strcmp(v, v
line 63:
left operand must be modifiable lvalue: op "="
line 66:
left operand must be modifiable lvalue: op "="
cc: acomp failed for ar2.c
Where did I go wrong? Please see attached
Please help me successfully complie...Thank you very much!!!!
CODE:
______________________________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SPELL_OKAY 0 /* success */
#define SPELL_FAILURE -1 /* general, unspecified failure */
#define SPELL_NOMEMORY 1 /* could not allocate more memory */
#define SPELL_NOTFOUND 2 /* could not find a file */
#define SPELL_TOOLONG 3 /* a word is too long */
#define SPELL_INCORRECT 4 /* a word is incorrect */
#define MAXLENGTH 64
#define EXTEND_SIZE 20
/*Function declarations*/
int max_word_len(void);
int add_word(char *word);
void forget_word(char *word);
void forget_all(void);
int read_dict(char *file);
int check_word(char *word);
int check_file(char *file, void (*badword)(char *));
int extend_dictionary ( void );
char *dup_string ( char *word );
int compare_fn ( const void *a, const void *b );
int binsearch( char *word, char *dict[], int n);
void swap(char *v[], int i, int j);
void quicksort(char *v[], int left, int right);
char *dictionary[] = {NULL};
int num_words = 0;
int max_words = 0;
int main ( )
{
int i;
add_word( "Now" );
add_word( "is" );
add_word( "the" );
add_word( "time" );
add_word( "for" );
add_word( "all" );
add_word( "good" );
for ( i = 0 ; i < num_words ; i++ ) {
printf( "Word %d is %s\n", i, dictionary );
}
return 0;
}
/* extends the dictionary in steps of 20 words */
int extend_dictionary (void)
{
char* temp[] = {NULL};
int new_size;
if ( num_words == max_words )
{
new_size = max_words + EXTEND_SIZE;
temp = (char *)realloc(dictionary, new_size * sizeof(char) );
if ( temp != NULL )
{
dictionary = temp;
max_words = new_size;
}
else
return SPELL_NOMEMORY;
}
return SPELL_OKAY;
}
/* make a copy of a string */
char *dup_string ( char *word )
{
char *temp = malloc( strlen(word) + 1 );
if ( temp != NULL )
{
strcpy( temp, word );
return temp;
}
else
return NULL;
}
int add_word ( char *word )
{ int iptr;
char *ptr;
if( strlen(word) > max_word_len() )
return SPELL_TOOLONG;
/*check if the word is in the dictionary*/
if (check_word(word) == SPELL_OKAY)
return SPELL_OKAY;
else
{ if ( (ptr = dup_string(word))== NULL )
return SPELL_NOMEMORY;
else if ( (iptr = extend_dictionary()) == SPELL_NOMEMORY )
return SPELL_NOMEMORY;
else
{
dictionary[num_words++] = dup_string( word );
quicksort( dictionary, 0, num_words-1);
return SPELL_OKAY;
}
}
}
int max_word_len(void)
{ return MAXLENGTH;
}
int check_word(char *word)
{
int i, len;
int bNumeric = 1;
int wordnum = 0;
/*check for length*/
len = strlen(word);
if ( len > max_word_len())
return SPELL_TOOLONG;
for (i=0; i<len; i++)
{
/*not a digit*/
if ( isdigit(word) == 0)
{
bNumeric = 0;
break;
}
}
if (bNumeric == 1)
return SPELL_OKAY;
else
{
wordnum = binsearch(word, dictionary, num_words);
if ( wordnum != -1)
return SPELL_OKAY;
else
return SPELL_INCORRECT;
}
}
int binsearch( char *word, char *dict[], int n)
{ int low, high, mid;
low=0;
high = n-1;
while(low <=high)
{ mid = (low + high)/2;
if ( compare_fn(word, dict[mid]) < 0)
high = mid -1;
else if ( compare_fn(word, dict[mid]) > 0 )
low=mid+1;
else
return mid;
}
return -1;
}
void quicksort(char *v[], int left, int right)
{ int i, last;
void swap (char*v[], int i, int j);
if (left >=right)
return ;
swap(v, left, (left+right)/2);
last = left;
for (i = left+1; i<=right; i++)
if ( strcmp(v, v
)<0)
swap (v, ++last, i);
swap(v, left, last);
quicksort(v, left, last-1);
quicksort(v, last+1, right);
}
void swap(char *v[], int i, int j)
{ char *temp;
temp = v;
v = v[j];
v[j] = temp;
}
void forget_word(char *word)
{
int i, wordnum;
void * ptr;
wordnum = binsearch(word, dictionary, num_words);
if (wordnum != -1)
{
num_words--;
for (i = wordnum; i < num_words; i++ )
dictionary = dictionary[i+1];
free(dictionary[wordnum]);
dictionary[num_words+1] = NULL;
}
}
void forget_all(void)
{
int i ;
for (i=0; i < num_words; i++)
{
free(dictionary);
}
free(dictionary);
max_words = 0;
num_words = 0;
}
int read_dict(char *file)
{
char *input;
FILE *fp;
char c;
int i = 0;
int result;
char word[MAXLENGTH];
if( (fp=fopen(file, "r"
) == NULL)
return SPELL_NOTFOUND;
forget_all();
while( c= (getc(fp))!=EOF)
{
if (isalnum(c) == 0)
{
if(strlen(word) != 0)
{
word = '\0';
i = 0;
if ( (result = add_word(word)) == SPELL_NOMEMORY || result == SPELL_FAILURE )
{
fclose(fp);
return result;
}
}
}
else
word[i++] = c;
}
fclose(fp);
return SPELL_OKAY;
}
int check_file(char *file, void (*badword)(char *))
{ char *input;
FILE *fp;
char c;
int i = 0;
int result;
char word[MAXLENGTH];
if( (fp=fopen(file, "r"
) == NULL)
return SPELL_NOTFOUND;
while( c= (getc(fp))!=EOF)
{
if (isalnum(c) == 0)
{
word = '\0';
i = 0;
if (check_word(word) == SPELL_INCORRECT)
{
if (badword != NULL)
badword(word);
fclose(fp);
return SPELL_INCORRECT;
}
else if ( result=check_word(word) == SPELL_FAILURE)
{
fclose(fp);
return SPELL_FAILURE;
}
}
else
word[i++] = c;
}
fclose(fp);
return SPELL_OKAY;
}
swap (v, ++last, i);
swap(v, left, last);
quicksort(v, left, last-1);
quicksort(v, last+1, right);
}
void swap(char *v[], int i, int j)
{ char *temp;
temp = v;
v = v[j];
v[j] = temp;
}
void forget_word(char *word)
{
int i, wordnum;
void * ptr;
wordnum = binsearch(word, dictionary, num_words);
if (wordnum != -1)
{
num_words--;
for (i = wordnum; i < num_words; i++ )
dictionary = dictionary[i+1];
free(dictionary[wordnum]);
dictionary[num_words+1] = NULL;
}
}
void forget_all(void)
{
int i ;
for (i=0; i < num_words; i++)
{
free(dictionary);
}
free(dictionary);
max_words = 0;
num_words = 0;
}
int read_dict(char *file)
{
char *input;
FILE *fp;
char c;
int i = 0;
int result;
char word[MAXLENGTH];
if( (fp=fopen(file, "r"
return SPELL_NOTFOUND;
forget_all();
while( c= (getc(fp))!=EOF)
{
if (isalnum(c) == 0)
{
if(strlen(word) != 0)
{
word = '\0';
i = 0;
if ( (result = add_word(word)) == SPELL_NOMEMORY || result == SPELL_FAILURE )
{
fclose(fp);
return result;
}
}
}
else
word[i++] = c;
}
fclose(fp);
return SPELL_OKAY;
}
int check_file(char *file, void (*badword)(char *))
{ char *input;
FILE *fp;
char c;
int i = 0;
int result;
char word[MAXLENGTH];
if( (fp=fopen(file, "r"
return SPELL_NOTFOUND;
while( c= (getc(fp))!=EOF)
{
if (isalnum(c) == 0)
{
word = '\0';
i = 0;
if (check_word(word) == SPELL_INCORRECT)
{
if (badword != NULL)
badword(word);
fclose(fp);
return SPELL_INCORRECT;
}
else if ( result=check_word(word) == SPELL_FAILURE)
{
fclose(fp);
return SPELL_FAILURE;
}
}
else
word[i++] = c;
}
fclose(fp);
return SPELL_OKAY;
}