I don't know if this is a great way to handle this - seems a bit clunky but may just need a function or logic tweak added to it.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 120
int main ()
{
FILE* glo;
char str[SIZE][SIZE] = {{'\0'}};
// char* str[1000];
char* filename = "glossary.txt";
char test[SIZE];
char *ptr;
int i, len;
int r=0;
printf("\n\n");
if (!(glo = fopen(filename,"r"))) {
printf("\nCannot open %s for output.\n",filename);
return 1;
}
ptr = NULL;
len = r = 0;
while(fgets(test,SIZE,glo) != NULL) {
ptr=strtok(test, " ");
if(ptr) {
strcpy(str[r], ptr);
len=strlen(str[r]);
if(str[r][len-1]=='\n')
str[r][len-1]='\0';
++r;
}
while(ptr) {
ptr = strtok(NULL, " ");
if(ptr) {
strcpy(str[r], ptr);
len=strlen(str[r]);
if(str[r][len-1]=='\n')
str[r][len-1]='\0';
++r;
}
}
}
i=0;
while(i<r) {
if(i % 20 == 0 && i) {
puts("\n\n press enter to display the next set of words");
(void) getchar();
}
printf("\n %d: %s ", i, str[i++]);
}
printf("\nEnter test word [class]: ");
scanf("%1023s",test);
printf("\nstr[2]:%s",str[1]);
printf("\nyours:%s",test);
if(strcmp(test,str[1])==0) {
printf("\nyes");
}
else {
printf("\nWrong command. \n");
}
fclose(glo);
return 0;
}
Burst out words from your "glossary.txt" file:
abstract
class
a
class
defined
to
make
creating
subclass
easier
array
an
ordered
collection
of
values
collection
class
that
used
for
grouping
and
manipulating
related
objects
compile
time
the
time
during
which
the
source
code
is
analyzed
and
converted
into
object
code
dictionary
a
collection
of
key/value
pairs
framework
a
collection
of
classes,
functions
and
protocols
that
are
related
to
support
certain
platform
instance
a
concrete
representation
of
a
class
message
the
method
and
its
associated
arguments
that
are
sent
to
an
object
retain
count
a
count
of
the
number
of
times
an
object
is
referenced
selector
the
name
used
to
select
the
method
to
execute
for
an
object