#include <fcntl.h>
#include <sys/termios.h>
#include<sys/errno.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

main()

{
FILE *sfp;
int c;

sfp=fopen("/dev/ttyS2","w");
switch ( (int) sfp)
    {
    case ENXIO: {printf("Port does not exist.\n");
                 return;}
    case EBUSY: {printf("Device busy.\n");
                 return;}
    case EINTR: {printf("Open Interrupted.\n");
                 return;}
    case NULL:  {printf("Could not open device.\n");
                 return;}
    }
while ((c=getchar())!='Z')
    {
    fputc(c,sfp);   
    fflush(sfp);
    putchar(c);
    }
}
