Instructions:
A local company is developing a way to pass multiple messages to multiple places at the same time. It is one of those secret companies. You are to write a program that will extract only the text sent to a particular device and ignore the rest of the messages. Each message sent has an identifying two characters’ header (first being a $ followed by a single character) followed by a number indicating the size of the message that preceded $ tag symbol. (ie the actual message is in front of the identifier $tag. This is a new way to send message to fake out the folks who are monitoring your text trafficking.) You are to extract out only the set of messages (lines of text) that are addressed to you. Your identifying two characters is $Y so your program will only extract messages sent to $Y devices.
Example input:
oprfjiad093$X5abcdep0qj3 fqijfpiqjef$L21Your message to find.$Y21p9iqjv0$Ea0n wq9r r$K13Next Message.$Y1309q 4r9 qefkjad0$Tfu8;lkfdv98
Example output:
Your message to find.
Next Message.
Your test data for your program is found in the following file on blackboard
'MessagesAtEnd.txt'
You will read in the input text into an array of characters. Example char line[300]. You will use pointers to move through the array (ie no [ ]’s in your code.) and extract and print out your text.
Hello again. I am having trouble figuring out how to basically flag the system to read only the message meant for me. So far I don't have much, but we are only supposed to read the message if it is a $Y and then the next character after that tells the length of the message, then you read backwards. My idea was if as you are reading, the message has a $ and then a Y, read the number, then go backwards and read, but I'm having trouble figuring out what the syntax for that would be. I know my code is really wrong, but I was just wondering if someone could point me on how to approach this syntax-wise.
***WE HAVE NOT LEARNED VECTORS. HE DOES NOT WANT [] ANYWHERE EXCEPT THE INITIALIZATION OF THE ARRAY, BUT I WAS GOING TO GET IT WORKING FIRST THEN SWITCH THEM TO POINTERS****
Message
**********************************************************************
Enter message file: Enter real message file: $Zqva'HMQ[V$L01$M56On the twelfth day of Christmas my true love gave to me$Y55xN\t}h0{YS/L$X66The 1997 Chautauqua Program has been released. This is a faculty !-2_w2@~:M/u#$/$X71development program of the National Science Foundation. While much of ]gP0@uItU}1WkCS$L71the information is directed to science and mathematics, some of it is $L69twelve drummers drumming, eleven pipers piping, ten lords a-leaping,$Y68E9`$S60more general in nature and appropriate to all disciplines. $A01$G68nine ladies dancing, eight maids a-milking, seven swans a-swimming,$Y67DFIaZ\^zQ'NV$X73The short courses are usually three days long and are limited to around HtwGa&l+Lcgb$S6725 participants. The application requires a statement of interest $P37six geese a-laying, five gold rings$Y35;E~(s8Qr5YALv$X73explaining why you want to take the course and how you will use it when $G56four calling birds, three french hens, two turtle doves$Y55j$_eE]p$j4l$S68you return to your home institution. They are presented at various @R~Z,v>$M71locations around the country, including Atlanta, Memphis, and Dayton, $L32and a partridge in a pear tree.$Y31,6*`lWT$M06Ohio.s'$L01p}/dbbBXY$S16That's all folks?$Y17There an't no more cv03248(%$76.$Y1.ikjh7*&(^$&^ $y7The end
************************************************************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
//functions
void readCharacters(char message [])
{
int i;
for(i=0;i<29;i++) //kept it small to test first..I know all of this is wrong
{
if(message[i]=='$'&& message[i+1]=='Y'&& isdigit(message[i+2]))
{
infile>>message[i];
// cout<<message[i]<<endl;
}
cout<<message[i]<<" ";
}
}
int main()
{
infile.open("C:\\data\\input\\TestMessage.txt");
if(!infile)
{
cout<<"File did not open. Please try again.";
return 0;
}
char message[600]; //array to hold the encrypted message
char *ptr=nullptr; //was going to get it working before adding the pointers.
ptr=message;
int i;
readCharacters(message);
|