public
anonymous / capitalize.c
Created

C capitalize

  • Download Gist
capitalize.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <stdio.h>
#include <unistd.h>
 
int main(int argc, char **argv) {
int bread;
char buf[256 * 1024];
char *ptr, *end;
 
bread = read(0, buf, 256 * 1024);
int was_space = 1;
while (bread) {
ptr = buf;
end = ptr + bread;
while (ptr != end) {
char c = *ptr;
if ( (c >= 9 && c <=13) || c == 32)
was_space = 1;
else if ((c >= 97 && c <= 122) && was_space) {
*ptr &= ~32;
was_space = 0;
}
 
else if (was_space)
was_space = 0;
ptr++;
}
write(1, buf, bread);
bread = read(0, buf, 256 * 1024);
}
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.