/* file : simpleEncoding.c */ /* author : Oscar MirĂ³ (o.miro.i.lopez.feliu@student.rug.nl) */ /* Description: * Given a series of characters, encodes them. Adds n to their ascii value where n is * their position in the sentence. */ #include #include int main(int argc, char *argv[]) { int position = 1; char character; while(character = getchar()) { // (character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z'); // if you prefer if (isalpha(character)) { // checks capitalitzation of input, if output is not a letter it loops // the alphabet so its back into a letter if (isupper(character)){ character = (((character + position - 'A') % 26) + 'A'); } else if (islower(character)){ character = (((character + position - 'a') % 26) + 'a'); } } else if (character == '\n') { printf("\n"); return 0; } // print end result printf("%c", (character)); position++; } }