Filter.c convert to lowercase

From Initq

Jump to: navigation, search

Here is simple C code to convert uppercase to lowercase.

/* convert text to lowercase */
#include <stdio.h>  /* needed for getchar and putchar */
#include <ctype.h>  /* needed for toupper and tolower */
 
int main (void)
 
{
   int key;
 while ((key = getchar()) != EOF)
  {
    key = toupper(key);
    putchar(key);
  }
}

you can compile this by

[lexiana@initq 1]$ gcc -o filter filter.c

Output will look like this

[lexiana@initq 1]$ ./filter
PLEASE CONVERT ME TO LOWERCASE.
please convert me to lowercase.
COULD YOU di it AGAIN.
could you di it again.
^C

you can even sen files to it to convert to lower case.

[lexiana@initq 1]$ ./filter < mixed.txt
this is all upper case.
1
2
3
here it is again.
this is fine.
Personal tools