M
Michiel Rapati-Kekkonen
recently I was put on the right trail in the matter of searching in arrays
of structs.
I got it working, a bit.
Unfortunately, as soon as I want more, I'm stuck again:
it is basically a dictionary I'm trying to make.
I have a huge list of conjugated forms.
One can search that list to find a number, the index in another array, which
refers to the unconjugated word.
If it is not found in that array of forms, I want to search the array of
unconjugated words (it could be an adverb or such).
And here suddenly the 'trick' I have just learned stutters...
*
I made a struct
struct wordforms{
char *wordform; /*the conjugated wordform */
unsigned long orgnr; /*the indexnumber to the array of
unconjugated/not-conjugatable words */
unsigned short formname; /*the index to the name/type of
conjugation */
};
the array would be:
struct wordforms form_list[]={
{"aaaaab", 1, 3},
{"bbaacc", 9012, 4}
...,
{"zzzf", 876, 12}};
Searching would go
void
find_form (char *wordform)
{
struct wordforms target, *result;
target.wordform = wordform;
result = bsearch (&target, form_list, count, sizeof (struct
wordforms), wordf_cmp);
if (result){
print_wordf (result);
}
else
printf ("Couldn't find %s.\n", woordvorm);
}
Searching here goes well
It gives me the index to the original word, stored in another array of
structs
struct dictwords{
char orgword[28];
char meaning[100];
unsigned short wordtype_id;
};
and the array
struct dictwords word_list[]={
{"aaa", "meaning a", 1},
{"abb","meaning b",1},
...
{"zzz", meaning z", 2}};
BUT
When a word is not found I want to search that same word_list array, using
the same type of function as before.
However my compiler informs me that the
'=' : left operand must be l-value.
and it refers to the second line
target2.orgword = orgword
in that adapted function.
If I then change the declaration of the struct into
struct dictwords{
char *orgword;
char meaning[100];
unsigned short wordtype_id;
};
or
struct dictwords{
char *orgword;
char *meaning;
unsigned short wordtype_id;
};
compilation is allright in the first case
but building gives One Big Error:
Internal error during ReadSymbolTable
plus some (as you may have guessed, for me ununderstandable ) tables.
Why do the arrays respond differently to the same type of action?
Your help would be Most appreciated!
Michiel
of structs.
I got it working, a bit.
Unfortunately, as soon as I want more, I'm stuck again:
it is basically a dictionary I'm trying to make.
I have a huge list of conjugated forms.
One can search that list to find a number, the index in another array, which
refers to the unconjugated word.
If it is not found in that array of forms, I want to search the array of
unconjugated words (it could be an adverb or such).
And here suddenly the 'trick' I have just learned stutters...
*
I made a struct
struct wordforms{
char *wordform; /*the conjugated wordform */
unsigned long orgnr; /*the indexnumber to the array of
unconjugated/not-conjugatable words */
unsigned short formname; /*the index to the name/type of
conjugation */
};
the array would be:
struct wordforms form_list[]={
{"aaaaab", 1, 3},
{"bbaacc", 9012, 4}
...,
{"zzzf", 876, 12}};
Searching would go
void
find_form (char *wordform)
{
struct wordforms target, *result;
target.wordform = wordform;
result = bsearch (&target, form_list, count, sizeof (struct
wordforms), wordf_cmp);
if (result){
print_wordf (result);
}
else
printf ("Couldn't find %s.\n", woordvorm);
}
Searching here goes well
It gives me the index to the original word, stored in another array of
structs
struct dictwords{
char orgword[28];
char meaning[100];
unsigned short wordtype_id;
};
and the array
struct dictwords word_list[]={
{"aaa", "meaning a", 1},
{"abb","meaning b",1},
...
{"zzz", meaning z", 2}};
BUT
When a word is not found I want to search that same word_list array, using
the same type of function as before.
However my compiler informs me that the
'=' : left operand must be l-value.
and it refers to the second line
target2.orgword = orgword
in that adapted function.
If I then change the declaration of the struct into
struct dictwords{
char *orgword;
char meaning[100];
unsigned short wordtype_id;
};
or
struct dictwords{
char *orgword;
char *meaning;
unsigned short wordtype_id;
};
compilation is allright in the first case
but building gives One Big Error:
Internal error during ReadSymbolTable
plus some (as you may have guessed, for me ununderstandable ) tables.
Why do the arrays respond differently to the same type of action?
Your help would be Most appreciated!
Michiel