Click here to Skip to main content
13,766,627 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Write an ANSI-C Application to parse received packets of data from the command line interface (CLI).
One packet is always constructed in the following way:
<sep>RCV<sep>SOME:DATA<length><sep><sep>OK<sep>
whereas <sep> as a keyword separator will be \r\n.
The input string might contain multiple packets, but the maximum allowed input is 1024 bytes (whole CLI input, incl. keywords).
At first, the application reads input length, e.g. 197, from CLI and then reads 197 bytes from CLI. Those 197 bytes might contain several encoded packets, none, or even incomplete ones.Input
197
\r\nRCV\r\nSOME:DATA40\r\n24Ab2bfsdfa46jKjj936100dsasgdfsdf1240s0x\r\nOK\r\n\r\nRCV\r\nSOME:DATA50\r\n24Ab246324400123543gfdsas4sdaasd22231fn67sdff46ngk\r\nOK\r\n\r\nRCV\r\nSOME:DATA0\r\n\r\nOK\r\n

Expected output: 3 complete packets after parsing
Packet 1> size: 40 data: 24Ab2bfsdfa46jKjj936100dsasgdfsdf1240s0x
Packet 2> size: 50 data: 24Ab246324400123543gfdsas4sdaasd22231fn67sdff46ngk
Packet 3> size: 0 data:

What I have tried:

As i said that i am new to this.so i just applied strtok but it just split the function but the remaining logic is still not clear to me
Posted 5 days ago
Updated 5 days ago
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This is your assignment so you are expected to do the work. If you really do not understand it then you should be talking to your teacher.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Quote:
As i said that i am new to this.so i just applied strtok but it just split the function but the remaining logic is still not clear to me

What you have done is mystery to us, because you didn't show anything.

You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

You need to visit some Learn C tutorial to learn the basics of the lanuage.

Your task is to read and interpret a data buffer and work with. C has the native data type char in which so have a every byt. With iteratig about it you can read eache byte.
char *data =// your data
if( (data[0] == '\r') && (data[1] == '\n')) {
// seperator found
} 
tip: write clear code with function and explaining names
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181114.1 | Last Updated 11 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100