Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- int file_eof(FILE *in) // could use "int *ch" to avoid seeking
- {
- if(!in) return -1;
- int c;
- c = fgetc(in);
- if(c == EOF) return 1;
- c = fseek(in, -1, SEEK_CUR);
- if(c != 0)
- return -2;
- return 0;
- }
- int file_eofHandle(FILE *in)
- {
- int c = file_eof(in);
- if(c < 0)
- {
- printf("[-] file_eof() [%d]\n", c);
- exit(1);
- }
- if(c == 1)
- exit(0); // should use fclose(in), but program termination closes it
- return 0;
- }
- int main(int argc, char **argv)
- {
- FILE *in, *out;
- int c;
- int sBegin = 1; // beginning of sentence
- if(argc < 2)
- return 1;
- in = fopen(argv[1], "r");
- if(!in)
- return 2;
- out = stdout; // there's no need to write to a file
- // that's what piping is for
- // if using *nix system file descriptor, then stdout is 1
- while(1)
- {
- file_eofHandle(in);
- c = fgetc(in);
- if(c == '.')
- sBegin = 1;
- if(isalpha(c) != 0) // using if((c >= 0xwhatever && c <= 0xwhatever) ||
- { // (blah >= lakjsdflkj...)) is harder to read
- // and a function should be used anyway
- if(sBegin != 0)
- {
- c = toupper(c);
- fputc(c, out);
- sBegin = 0;
- }
- else
- fputc(c, out);
- }
- else
- fputc(c, out);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement