Posted By

ozkriff on 05/16/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tandouri


analyze text


 / Published in: C
 

  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. int main() {
  5. const int l_block = 1024;
  6.  
  7. FILE* input_text_file;
  8. long n = 0, i = 0, j = 0;
  9. int meet_comma = 0;
  10. long file_lengh;
  11. char* buffer;
  12. int num_block;
  13.  
  14.  
  15. input_text_file = fopen( "../../additional_files/en.txt", "r" );
  16. if ( !input_text_file ) {
  17. puts( "Can't open file!" );
  18. return 1;
  19. }
  20.  
  21. fseek( input_text_file, 0, SEEK_END );
  22. file_lengh = ftell( input_text_file );
  23. buffer = (char*) malloc( (file_lengh + 1) * sizeof(char) );
  24.  
  25. num_block = file_lengh / l_block;
  26. fseek( input_text_file, 0, SEEK_SET );
  27. fread( buffer, l_block, num_block + 1, input_text_file );
  28. buffer[file_lengh] = '\0';
  29.  
  30. /* ----------------------------- PROCESSING ------------------------------ */
  31.  
  32. while( buffer[i]) {
  33. switch ( buffer[i] ) {
  34. case ',':
  35. meet_comma = 1;
  36. break;
  37. case '.':
  38. case '!':
  39. case '?':
  40. if ( !meet_comma ) /* Если запятой небыло. */
  41. for ( j = n; j <= i; j++ )
  42. putchar( buffer[j] );
  43. meet_comma = 0;
  44. n = i + 1;
  45. break;
  46. default: break;
  47. }
  48. i++;
  49. }
  50.  
  51. /* ------------------------------------------------------------------------- */
  52.  
  53. fclose ( input_text_file );
  54. free(buffer);
  55. puts("");
  56.  
  57. return 0;
  58. }

Report this snippet  

You need to login to post a comment.