Advertisement
Shanix

Untitled

Mar 17th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. int indexCase = 1;
  2. if ( index == 0 ) { // Word on top edge
  3. strcpy( nearest[0], wordLines[index] );
  4. strcpy( nearest[1], wordLines[index + 1] );
  5. actualLength--;
  6. indexCase = 0;
  7. } else if ( index == textSize - 1 ) { // Word on bottom edge
  8. strcpy( nearest[1], wordLines[index - 1] );
  9. strcpy( nearest[2], wordLines[index] );
  10. actualLength--;
  11. } else { // General case: word not on edge.
  12. strcpy( nearest[0], wordLines[index - 1] );
  13. strcpy( nearest[1], wordLines[index] );
  14. strcpy( nearest[2], wordLines[index + 1] );
  15. }
  16.  
  17. // Now we check for that word.
  18. bool foundWord = false;
  19. for ( int i = 0; i < actualLength; i++ ) {
  20. if ( i == indexCase ) {
  21. if ( strstr( nearest[i], word ) != NULL ) { // checking bigger string.
  22. char *lineBackup = calloc( strlen( nearest[i] ), sizeof( char ) );
  23. strcpy( lineBackup, nearest[i] );
  24. char *token = strtok(nearest[i], " ");
  25. while ( token != NULL ) {
  26. if ( strstr( token, word ) != NULL ) { // Obama to public: We got 'im.
  27. foundWord = true;
  28. markMisspelled( token );
  29. int pos = token - nearest[i];
  30. printRemaining( lineBackup, pos, token );
  31. break;
  32. } else { // we got the wrong guy... er, word, so let's just print it.
  33. printf("%s ", token);
  34. }
  35. token = strtok( NULL, " " ); // seriously this threw me off so bad.
  36. }
  37. free( lineBackup );
  38. printf("\n");
  39. }
  40. } else {
  41. printf( "%s\n", nearest[i] );
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement