Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Prints the context lines surrounding the incorrect word/word not found in
- * the provided dictionary. Finds the incorrect word and higlights it red.
- */
- void printContext(char **textLines, char *word, int index, int textSize )
- {
- printf("\n");
- char **context = malloc( LOCAL_LINES_MAX * sizeof( char * ) );
- for( int i = 0; i < LOCAL_LINES_MAX; i++ ) {
- context[i] = ( char * ) malloc( INPUT_SIZE * sizeof ( char ) );
- }
- if ( index == 0 ) { // word is on the first line
- strcpy( context[0], textLines[index] );
- strcpy( context[1], textLines[index + 1] );
- strcpy( context[2], textLines[index + 2] );
- } else if ( index == textSize - 1 ) { // Word is on the last line
- strcpy( context[0], textLines[index - 2] );
- strcpy( context[1], textLines[index - 1] );
- strcpy( context[2], textLines[index] );
- } else { // Word within text file
- strcpy( context[0],textLines[index - 1] );
- strcpy( context[1], textLines[index] ) ;
- strcpy( context[2], textLines[index + 1] );
- }
- // Examine each line and check for the word
- for( int i = 0; i < LOCAL_LINES_MAX; i++ ) {
- if ( strstr( context[i], word ) != NULL ) {
- char *token = strtok(context[i], " ");
- while ( token != NULL ) {
- if ( strstr( token, word ) != NULL ) { // token is the word
- markMisspelled( token );
- } else { // token is not the word, so print the token
- printf("%s ", token);
- }
- token = strtok( NULL, " " );
- }
- printf("\n");
- } else {
- printf( "%s\n", context[i] );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement