Write a program in C not c not c Write a program takes messa

Write a program in C, (not c++ not c#)

Write a program takes messages from a standard input or a file in a loop, collects the messages in a cache, and then invokes a function message_dispatcher() to print a content of every message in the cache. The cache should be no larger than 16 messages.

Messages can have a number of formats:

TYPE 1: 16 characters

TYPE 2: 4 integers

TYPE 3: 2 floating point numbers

TYPE 4: 4 five-character words

The input should indicate the type of the message and the content; e.g.:

1 abcdefghijklmnop
2 123 45 6 7890
3 123.34 23.12345
4 aaaaa bbbbb ccccc ddddd

Your program should stop after receiving the end of file indicator.

The function should take the message as a parameter, recognize what type the message has, and then print the message accordingly along with the type:

16 characters in one line with no space

4 integers separated by commas

both floating numbers separated by a slash

4 words separated by spaces

For example:

TYPE 1: abcdefghijklmnop
TYPE 2: 123,45,6,7890
TYPE 3: 123.34/23.12345
TYPE 4: aaaaa bbbbb ccccc ddddd

Your program should use the union construct of C. Each message should include a field type that is common to all messages and indicates the type of the message. You should use an unsigned short as the data type for the message type field.

Solution

#include<iostream>

#include<stdio.h>

void dispatcher(vector<string>&d)

{

int i;

for(i=0;i<d.size();i++)

cout<<d[i];

}

void main()

{

vector<string>cache(16);

for(i=0;i<16;i++)

cin>>v[i];

dispather(v);

}

Write a program in C, (not c++ not c#) Write a program takes messages from a standard input or a file in a loop, collects the messages in a cache, and then invo
Write a program in C, (not c++ not c#) Write a program takes messages from a standard input or a file in a loop, collects the messages in a cache, and then invo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site