Hi, I'm trying to write a simple spell-check program where the user enters one word at a time, but I'm having trouble terminating the program when the user is finished. I would like the program to finish accepting input when they user enters a period. This is what I've got, any help would be appreciated.
Code:
#include<stdio.h>
#include<string.h>
#define SIZE 46000
#define WORD_SIZE 128
int main( void )
{
// Reads linux.words into buffer array
FILE *dict;
dict = fopen( "linux.words", "r" );
if( ! dict )
{
printf( "Failed to input linux.words\n" );
return 1;
}
char buffer[SIZE][WORD_SIZE];
int i = 0;
while ( fgets( buffer[i] , SIZE, dict ) != NULL ) {
i++;
}
char word[99][29];
int j;
// This for loop reads one word at a time from the user
// and stores the words in an array to be encoded later.
for( j=0; j<100; j++ )
{
printf( "Enter a word( . to quit )\n" );
fgets( word[j], 31, stdin );
if( (strcmp( word[j], "." )) == 1 )
j=100;
}
return 0;
}
With this the program only takes one word and then quits.
Thanks.