/*
Name

  upper.c

Synopsis

  upper input-file output-file

Description

  Reads an input file and creates a similar output
  file in which all lowercase characters have been
  converted to upper case.

  This is a simple demonstration of file functions,
  namely: fopen(), fclose(), fprintf(), getc(), and 
  putc().  stderr and perror() are also demonstrated.

Ray Ontko, 1999/11/28
*/

#include <stdio.h>
#include <ctype.h>

int main( int argc , char *argv[] )
{
  int c ;
  FILE *infile ;
  FILE *outfile ;

  if( argc != 3 )
  {
    fprintf( stderr , "usage: %s infile outfile\n" , argv[0] ) ;
    return 1 ;
  }

  if( ( infile = fopen( argv[1] , "r" ) ) == NULL )
  {
    fprintf( stderr , "%s: unable to open \"%s\" for input\n" , 
      argv[0] , argv[1] ) ;
    perror( argv[0] ) ;
    return 1 ;
  }

  if( ( outfile = fopen( argv[2] , "w" ) ) == NULL )
  {
    fprintf( stderr , "%s: unable to open \"%s\" for output\n" , 
      argv[0] , argv[2] ) ;
    perror( argv[0] ) ;
    return 1 ;
  }

  while( ( c = getc( infile ) ) != EOF )
  {
    if( islower( c ) )
      c = toupper( c ) ;
    putc( c , outfile ) ;
  }

  fclose( infile ) ;
  fclose( outfile ) ;

  return 0 ;
}
