Advertisement
Guest User

main.c

a guest
Mar 28th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include "mystring.h"
  5.  
  6. int fTerminate(char ch, int * pbDiscardChar);
  7.  
  8. int main(int argc, char ** argv) {
  9.     MYSTRING str;
  10.     FILE * in;
  11.  
  12.     if((str = mystring_init_default()) == MYSTRING_STATUS_ERROR) {
  13.         printf("Error initializing MYSTRING object.\n");
  14.         return -1;
  15.     }
  16.  
  17.     if((in = fopen("book.txt", "r")) == NULL) {
  18.         printf("Error opening file \"book.txt\". Does the file exist?\n");
  19.         return -1;
  20.     }
  21.  
  22.     while(mystring_input(str, in, 1, fTerminate) != MYSTRING_STATUS_ERROR) {
  23.         if(mystring_size(str) == 4) {
  24.             mystring_output(str, stdout);
  25.             printf("\n");
  26.         }
  27.     }
  28.  
  29.     mystring_destroy(&str);
  30.  
  31.     return 0;
  32. }
  33.  
  34. int fTerminate(char ch, int * pbDiscardChar) {
  35.     // Terminate on whitespace characters or non-alpha characters.
  36.     return (*pbDiscardChar = ((isspace(ch) || (isalpha(ch) == 0))?1:0));
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement