Review of Basic References
#include <ctype.h>
#include <stdio.h>
#include <signal.h>
#define CTRL_H '\010'
#define CARRIAGE_RETURN '\015'
main(int argc, char *argv[])
{
FILE *fpin, *fpout;
int c;
struct sigaction sa;
char command[80], outfile[80];
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
sa.sa_handler = SIG_IGN;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGTSTP, &sa, NULL);
if (argc != 2)
{
printf("Usage: %s infile\n", argv[0]);
exit(1);
}
sprintf(command,"script %s", argv[1]);
system(command);
if ((fpin = fopen(argv[1], "r")) == NULL)
{
printf("Cannot open input file: %s\n", argv[1]);
exit(2);
}
sprintf(outfile, "%s.adgkmx", argv[2]);
if ((fpout = fopen(outfile, "w+")) == NULL)
{
printf("Cannot open output file: %s\n", argv[2]);
exit(3);
}
while( (c = fgetc(fpin)) != EOF)
{
if (c == CTRL_H)
{
fseek(fpout, -1L, SEEK_CUR);
}
else if (c == CARRIAGE_RETURN)
{
continue;
}
else if (iscntrl(c) && !isspace(c))
{
continue;
}
else
{
fputc(c, fpout);
}
}
rename(outfile, argv[1]);
}