Advertisement
Shanix

Untitled

Mar 16th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /**
  2. * Prints the context lines surrounding the incorrect word/word not found in
  3. * the provided dictionary. Finds the incorrect word and higlights it red.
  4. */
  5. void printContext(char **textLines, char *word, int index, int textSize )
  6. {
  7. printf("\n");
  8. char **context = malloc( LOCAL_LINES_MAX * sizeof( char * ) );
  9. for( int i = 0; i < LOCAL_LINES_MAX; i++ ) {
  10. context[i] = ( char * ) malloc( INPUT_SIZE * sizeof ( char ) );
  11. }
  12. if ( index == 0 ) { // word is on the first line
  13. strcpy( context[0], textLines[index] );
  14. strcpy( context[1], textLines[index + 1] );
  15. strcpy( context[2], textLines[index + 2] );
  16. } else if ( index == textSize - 1 ) { // Word is on the last line
  17. strcpy( context[0], textLines[index - 2] );
  18. strcpy( context[1], textLines[index - 1] );
  19. strcpy( context[2], textLines[index] );
  20. } else { // Word within text file
  21. strcpy( context[0],textLines[index - 1] );
  22. strcpy( context[1], textLines[index] ) ;
  23. strcpy( context[2], textLines[index + 1] );
  24. }
  25.  
  26. // Examine each line and check for the word
  27. for( int i = 0; i < LOCAL_LINES_MAX; i++ ) {
  28. if ( strstr( context[i], word ) != NULL ) {
  29. char *token = strtok(context[i], " ");
  30. while ( token != NULL ) {
  31. if ( strstr( token, word ) != NULL ) { // token is the word
  32. markMisspelled( token );
  33. } else { // token is not the word, so print the token
  34. printf("%s ", token);
  35. }
  36. token = strtok( NULL, " " );
  37. }
  38. printf("\n");
  39. } else {
  40. printf( "%s\n", context[i] );
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement