Skip to content

Instantly share code, notes, and snippets.

@themasch
Created August 9, 2011 15:13
Show Gist options
  • Save themasch/1134326 to your computer and use it in GitHub Desktop.
Save themasch/1134326 to your computer and use it in GitHub Desktop.
upper stdin
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MAXLINE 4096
int main(int argc, char** argv){
char line[MAXLINE];
int n, i, fd;
while(1) {
n = read(STDIN_FILENO, line, MAXLINE);
if(n < 0) {
perror("error in read: ");
return -1;
}
printf("n = %d\n", n);
if(n <= 0){
printf("break n = %d \n", n);
break;
}
for(i = 0; i < n; i++){
line[i] = toupper(line[i]);
}
write(STDOUT_FILENO, line, n);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment