Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include "mystring.h"
- int fTerminate(char ch, int * pbDiscardChar);
- int main(int argc, char ** argv) {
- MYSTRING str;
- FILE * in;
- if((str = mystring_init_default()) == MYSTRING_STATUS_ERROR) {
- printf("Error initializing MYSTRING object.\n");
- return -1;
- }
- if((in = fopen("book.txt", "r")) == NULL) {
- printf("Error opening file \"book.txt\". Does the file exist?\n");
- return -1;
- }
- while(mystring_input(str, in, 1, fTerminate) != MYSTRING_STATUS_ERROR) {
- if(mystring_size(str) == 4) {
- mystring_output(str, stdout);
- printf("\n");
- }
- }
- mystring_destroy(&str);
- return 0;
- }
- int fTerminate(char ch, int * pbDiscardChar) {
- // Terminate on whitespace characters or non-alpha characters.
- return (*pbDiscardChar = ((isspace(ch) || (isalpha(ch) == 0))?1:0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement