This is basically a ROT2 encryption program that actually only deals with letters and interchanging certain punctuation characters. The problem I have is that I get ridiculous number for the number of punctuation chars I'm supposed to count up. Maybe I'm implementing the ispunct() function wrong, or I'm not looking at the right variable. Who knows?
CODE
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char convert( char );
int main () {
char line[96], *line_ptr, output[96];
int index, lines_processed, punct_chars;
lines_processed = 0;
punct_chars = 0;
for( lines_processed = 0; 1; ++lines_processed ) {
printf( "Input a line> " );
line_ptr = fgets( line, 96, stdin );
if( line_ptr != line || line_ptr[0] == EOF ) break;
for( index = 0; index < 96; ++index ) {
if( ispunct( (int)line_ptr[index] ) ) ++punct_chars;
output[index] = convert( line_ptr[index] );}
printf( "%s%s", line_ptr, output );
}
printf( "\n%d lines processed, %d punctuation characters.\n", lines_processed, punct_chars );
return 0;
}
char convert( char input ) {
if( ((int)input >= 'A' && (int)input < 'Y') || ((int)input >= 'a' && (int)input < 'y') ) { input+= 2;}
else if( (int)input == 'Y' || (int)input == 'Z' || (int)input == 'y' || (int)input == 'z' ) { input-= 24;}
if( (int)input == '(' ) { input+= 1;}
else if( (int)input == ')' ) { input-= 1;}
if( (int)input == '[' || (int)input == '{' || (int)input == '<' ) { input+= 2;}
else if( (int)input == ']' || (int)input == '}' || (int)input == '>' ) { input-= 2;}
return input;
}
I haven't commented the code yet, but it should be a pretty straightforward design. If need be I can repost once I comment it.