Question
I need help implementing the following code without using filehandling and only getchar(); this is the prompt The input for your program will be a
I need help implementing the following code without using filehandling and only getchar(); this is the prompt
"The input for your program will be a text file containing a large amount of English. Typically, an English sentence ends with a period (aka, dot). Many years ago, when people used mechanical typewriters, the proper form was to place one space between words in a sentence, but two spaces after the period at the end of the sentence. This rule is no longer taught, since word processors automatically control spacing. Your program must extract the secret message from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0s and 1s. Each block of 8-bits is the ASCII encoding of a single character in the secret message. Your program will scan the input, and for each period (aka, dot) encountered, your program will count the number of spaces (ASCII 0x20) that immediately follow the dot. If the number of spaces is 0, then your program will ignore that dot completely. If the number of spaces is 1, then that corresponds to a single 0 bit of the secret message. If the number of spaces is 2, then that corresponds to a single 1 bit of the secret message. Finally, if the number of spaces is 3 or more, then that indicates that there are no more characters in the secret message. Your program must scan the input file, and output to stdout the plain text secret message. If your program successfully completes its task, then the program should return an exit status of 0 to the operating system. If the number of bits in the message is not a multiple of 8 (8 bits for each ASCII character), then your program should return an exit status of 1. If the input file does not containing the message over signal, i.e., a dot followed by 3 or more spaces, then your program should return an exit status of 2."
and this is my code
#include
int main(){ char ch; int count = 0; int secretMessage = 0; int bit = 0; int flag = 0; while ((ch = getchar()) != EOF){ while ((ch = getchar()) == '.'){
while ((ch = getchar()) == ' '){
if(ch==' ') { count++; } else { break;} }
if(count == 2){ int mask=1< bit++;} else if(count >= 3){ flag = 1; break; if(bit == 8){ bit = 0; printf("%c", secretMessage); secretMessage = 0; } } } } if(bit != 0){ return(1); } if(flag == 0){ return(2); } return 0; } i am not sure where i went wrong
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started