/* Name: ex8-6.c Purpose: B1FF filter : practice with one dimensional arrays Author: Bill Slough */ #include #include #include #define N 80 /* maximum length of input line */ int main() { char line[N]; /* holds one line of input */ int i; int lineLength; char ch; bool lineOverflow; /* Get a line of input, being careful not to overfill the buffer */ printf("Enter message: "); i = 0; while (i < N && (ch = getchar()) != '\n') { line[i++] = ch; } lineLength = i; lineOverflow = (lineLength == N) && (getchar() != '\n'); /* Terminate execution if there were too many input characters */ if (lineOverflow) { printf("Error in input: buffer overflow.\n"); return 1; } /* translate and output the coded message */ printf("In B1FF speak: "); for (i = 0; i < lineLength; i++) { ch = toupper(line[i]); switch(ch) { case 'A': ch = '4'; break; case 'B': ch = '8'; break; case 'E': ch = '3'; break; case 'I': ch = '1'; break; case 'O': ch = '0'; break; case 'S': ch = '5'; break; } printf("%c", ch); } printf("!!!!!!!!!!\n"); return 0; }