Name: Anonymous 2009-02-12 23:01
I need help with getting my code to read and output a file into ROT13.
here's what i have so far.
#include <stdio.h>
#include <ctype.h>
#include <fstream>
main(int argc, char *argv[])
{
FILE *input = stdin;
char *prog = argv[0];
int ch;
printf("ROT13 Encoder\n");
if(argc == 2)
if((input = fopen(*++argv, "r")) == NULL)
{
fprintf(stderr, "ERROR: %s can not open file %s.n", prog, *argv);
return 1;
}
while((ch = fgetc(input)) != EOF)
{
if(isalpha(ch))
{
if(toupper(ch) < ('A' + 13))
putchar(ch+13);
else
putchar(ch-13);
}
else
putchar(ch);
}
fclose(input);
return 0;
}
here's what i have so far.
#include <stdio.h>
#include <ctype.h>
#include <fstream>
main(int argc, char *argv[])
{
FILE *input = stdin;
char *prog = argv[0];
int ch;
printf("ROT13 Encoder\n");
if(argc == 2)
if((input = fopen(*++argv, "r")) == NULL)
{
fprintf(stderr, "ERROR: %s can not open file %s.n", prog, *argv);
return 1;
}
while((ch = fgetc(input)) != EOF)
{
if(isalpha(ch))
{
if(toupper(ch) < ('A' + 13))
putchar(ch+13);
else
putchar(ch-13);
}
else
putchar(ch);
}
fclose(input);
return 0;
}