fork download
  1. /*
  2.  * simpleEncode.c
  3.  *
  4.  * reads in a permutation of the alphabet then encodes
  5.  * lower case letters using that permutation
  6.  * module 4 template code you asked for - might need some cleaning up...
  7. *
  8.  * Created by Julian Saknussemm on 11/09/1752
  9.  * Licensed under Creative Commons BY 3.0.
  10.  *
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <assert.h>
  16.  
  17. #define STOP -1
  18. #define ALPHABET_SIZE 26
  19.  
  20. char encode (int plainChar, char *permuation);
  21. void testEncode (void);
  22.  
  23. int main (int argc, char *argv[]) {
  24.  
  25. testEncode();
  26.  
  27. //char permutation[ALPHABET_SIZE];
  28. //
  29. //scanf ("%s", permutation);
  30. //
  31. //// getchar() reads and returns one character from the keyboard
  32. //// returns -1 when the input is finished / end-of-file is reached
  33. //// signal this from the kayboard by pressing ^D in linux/^Z windows
  34. //int plainCharacter = getchar();
  35. //while (plainCharacter != STOP) {
  36. // int encodedCharacter = encode (plainCharacter, permutation);
  37. // printf ("%c", encodedCharacter);
  38. // plainCharacter = getchar();
  39. //}
  40. return EXIT_SUCCESS;
  41. }
  42.  
  43. void testEncode (void) {
  44. assert (encode ('A',"abcdefghijklmnopqrstuvwxyz") == 'A');
  45. assert (encode ('?',"abcdefghijklmnopqrstuvwxyz") == '?');
  46. assert (encode (' ',"abcdefghijklmnopqrstuvwxyz") == ' ');
  47. assert (encode ('\n',"abcdefghijklmnopqrstuvwxyz") == '\n');
  48.  
  49. assert (encode ('a',"abcdefghijklmnopqrstuvwxyz") == 'a');
  50. assert (encode ('m',"abcdefghijklmnopqrstuvwxyz") == 'm');
  51. assert (encode ('z',"abcdefghijklmnopqrstuvwxyz") == 'z');
  52.  
  53. assert (encode ('a',"bcdefghijklmnopqrstuvwxyza") == 'b');
  54. assert (encode ('m',"bcdefghijklmnopqrstuvwxyza") == 'n');
  55. assert (encode ('z',"bcdefghijklmnopqrstuvwxyza") == 'a');
  56.  
  57. assert (encode ('a',"qwertyuiopasdfghjklzxcvbnm") == 'q');
  58. assert (encode ('b',"qwertyuiopasdfghjklzxcvbnm") == 'w');
  59. assert (encode ('z',"qwertyuiopasdfghjklzxcvbnm") == 'm');
  60. }
  61.  
  62. char encode (int plainChar, char *permuation) {
  63. // Initialization
  64. char returnValue;
  65. // Is an alphabetical character
  66. if('a' <= plainChar && plainChar <= 'z') {
  67. returnValue = &permutation + sizeof(int)*('a'+plainChar);
  68. } else if ('A' <= plainChar && plainChar <= 'Z'){
  69. returnValue = &permutation + sizeof(int)*('A'+plainChar);
  70. }
  71.  
  72. return returnValue;
  73. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘encode’:
prog.c:67:18: error: ‘permutation’ undeclared (first use in this function)
   returnValue = &permutation + sizeof(int)*('a'+plainChar);
                  ^~~~~~~~~~~
prog.c:67:18: note: each undeclared identifier is reported only once for each function it appears in
stdout
Standard output is empty