/* ASCII to Binary Converter (15pt) Write a complete C program that takes a character array and prints its letters in binary format on the screen. You can assume that the character array is hardcoded in the program. In other words, you don't have to read it from the keyboard. The following will suffice: //char text[] = "Secret Message"; char text[] = "Halloween"; To test the program you can keep several text messages (commented out) and uncomment only one for testing. The program must automatically figure out the length of the message by scanning the array until it finds a character with an ASCII value of 0 (i.e., the standard string termination character '\0'). Each letter of the message must be printed on a single line as an 8-bit binary number that corresponds to the ASCII code of the letter (see the sample runs below). The program must define and call a function that does the ASCII to binary conversion for each letter and also prints the letter. The termination character should not be printed as part of the message. Sample Run #1: Halloween 01001000 01100001 01101100 01101100 01101111 01110111 01100101 01100101 01101110 Sample Run #2: Secret Message 01010011 01100101 01100011 01110010 01100101 01110100 00100000 01001101 01100101 01110011 01110011 01100001 01100111 01100101 */ #include #include #include #define DEBUG 0 void printBinary(char c) { int b[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // store the binary number here int n = c; // convert the char to int and work with n from now on if(DEBUG) printf("%3d: ", c); int i=0; while (n != 0) // convert to binary { b[i++] = n%2; n/=2; } for(i=7; i>=0; i--) // print the 8-bit binary number printf("%d", b[i]); } int main() { int i; //char text[] = "Secret Message"; //char text[] = "Halloween"; //char text[] = "Cat"; char text[] = "Hello"; for(i=0; text[i] != '\0'; i++) printf("%c", text[i]); printf("\n"); for(i=0; text[i]!= '\0'; i++) // print the encoded message { printBinary(text[i]); printf("\n"); } printf("\n"); system("pause"); }