tailieunhanh - C Programming for the Absolute Beginner phần 7

Tham khảo tài liệu 'c programming for the absolute beginner phần 7', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | C Programming for the Absolute Beginner Second Edition main char myString 21 0 int i Selecti on 0 int iRand srand time NULL iRand rand 4 1 random 1-4 while iSelection 4 printf n n1 tEncrypt Clear Text n printf 2 tDecrypt Cipher Text n printf 3 tGenerate New Key n printf 4 tQuit n printf nSelect a Cryptography Option scanf d iSelection switch iSelection case 1 printf nEnter one word as clear text to encrypt scanf s myString encrypt myString iRand break case 2 printf nEnter cipher text to decrypt scanf s myString decrypt myString iRand break case 3 iRand rand 4 1 random 1-4 printf nNew Key Generated n Chapter 7 Pointers break end switch end loop end main void encrypt char sMessage int random int x 0 encrypt the message by shifting each characters ASCII value while sMessage x sMessage x random x end loop x 0 printf nEncrypted Message is print the encrypted message while sMessage x printf c sMessage x x end loop end encrypt function void decrypt char sMessage int random int x 0 C Programming for the Absolute Beginner Second Edition x 0 decrypt the message by shifting each characters ASCII value while sMessage x sMessage x sMessage x - random x end loop x 0 printf nDecrypted Message is print the decrypted message while sMessage x printf c sMessage x x end loop end decrypt function Summary Pointers are variables that contain a memory address that points to another variable. Place the indirection operator in front of the variable name to declare a pointer. The unary operator is often referred to as the address of operator. Pointer variables should always be initialized with another variable s memory address with 0 or with the keyword NULL. You can print the memory address of pointers using the p conversion specifier. By default arguments are passed by value in C which involves making a copy of the incoming argument for the function to use. Pointers can be used to pass arguments by reference. Passing an array name to a pointer assigns the first memory location of the array