Reads from input and capitalizes everything. Shows how we can use EOF. In order to combine it with reading from a file, one can be inspired from here.

#include <stdio.h>

int main(void)
        int ch; /* Be careful! Declare ch as int because of getchar()
and EOF */
        ch = getchar(); /* Read first character */
        while (ch != EOF)
        { /* Go on if we didn't reach end of file */
                if (ch >= 'a' && ch <= 'z') /* If lower case letter */
                        ch = ch - ('a'-'A'); /* Move 'a'-'A' positions
                                                in the ASCII table */
                putchar(ch); /* Print out character */
                ch = getchar(); /* Read next character */
        return 0;

This code comes from ip course of DIT, Athens (Πληροφορική & Τηλεπικοινωνίες, ΕΚΠΑ)


One thought on “capitalize.c

  1. Pingback: EOF and getchar() problem

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s