Just seeking advice. I have a program for homework that I completed and runs great. The program encrypts letters. A = Z, B = Y, C = X etc. and adds 3 to ascii value for digits. The only problem is that Array index brackets should NOT APPEAR ANYWHERE in my code EXCEPT when i referr to the argv contents.
I am just seeking advice on how to go about removing the array index brackets, only line[] needs to be taken out. here is my code.
Code:#include <stdlib.h> #include <stdio.h> #include <string.h> #include<ctype.h> #define MAX_SIZE 256 char encryptAlpha (char strChar); char encryptNumber (char strNum); int main (int argc, char *argv[]) { int i; char **mover; FILE *fpIn; FILE *fpOut; char line[MAX_SIZE]; int size; for (i = 0; i < argc; i++) { printf("Argument %d is %s\n", i, argv[i]); } printf ("\n"); for (mover = argv; *mover != NULL; mover++) { printf("Argument pointed at by mover is %s\n", *mover); } if(!(fpIn = fopen(argv[1], "r" )) ) { printf( "Error opening the input file.\n" ); exit(101); } if(!(fpOut = fopen(argv[2], "w" )) ) { printf( "Error creating output file.\n" ); exit(101); } while(fgets(line, MAX_SIZE, fpIn)) { size = strlen(line); for (i = 0; i < size; i++) { if isalpha(line[i]) line[i] = encryptAlpha(line[i]); else if ((line[i] >= '0') && (line[i] <= '9')) line[i] = encryptNumber(line[i]); } fprintf (fpOut, "%s", line); } } char encryptAlpha (char strChar) { // Local Definitions char firstChar; char lastChar; // Statements if ((strChar >= 'A') && (strChar <= 'Z')) { firstChar = 'A'; lastChar = 'Z'; { while ((firstChar <= 'M') && (lastChar >= 'N')) { if (strChar == firstChar) strChar = lastChar; else if (strChar == lastChar) strChar = firstChar; firstChar++; lastChar--; } } } if ((strChar >= 'a') && (strChar <= 'z')) { firstChar = 'a'; lastChar = 'z'; { while ((firstChar <= 'm') && (lastChar >= 'n')) { if (strChar == firstChar) strChar = lastChar; else if (strChar == lastChar) strChar = firstChar; firstChar++; lastChar--; } } } return strChar; }// encryptAlpha char encryptNumber (char strNum) { strNum += 3; return strNum; }



LinkBack URL
About LinkBacks


