|
-
May 23rd, 2011, 01:49 AM
#1
[RESOLVED] Parsing Data
Hi all,
I'm in the process of writing a Client / Server Application, the Server is a PC and the Client is a Nintendo DS. The server side is written VB and the Client in C. I've got it working but I'm not convinced that my C code is up to much.
There's a very simple application protocol but I seem to have to use a lot of code to actually parse the data received from the Server. Below is the code I am currently using. Is there a better way of performing the parsing operation ?
Code:
/*
If a confirmation of connection was received (0x02)
tell the user we're connected.
Otherwise parse the data received
and take appropriate action
App. Protocol:
Hex(02) Successfully Connected to Controller
D,char where char is Date
L,char where char is the Location
R,int where int = Number Rounds
Q,int where int = Number of Questions (Not Implemented yet)
T,char where char = Team Name
*/
if (strncmp(recBuff,"\x02",1) == 0)
{
printTop("Connected");
}
else
{
if(sscanf(recBuff,"%c,",&cmd) == 1)
{
if(strncmp(&cmd,"D",1) == 0)
{
if(sscanf(recBuff,"%c,%[^\n]s",&cmd,argcharD) == 2)
{
printat(1,1,argcharD);
}
}
if(strncmp(&cmd,"L",1) == 0)
{
if(sscanf(recBuff,"%c,%[^\n]s", &cmd,argcharL) == 2)
{
printat(1,2,argcharL);
}
}
if(strncmp(&cmd,"R",1) == 0)
{
if(sscanf(recBuff,"%c,%d",&cmd,&num) == 2)
{
Do_RoundButtons(num); }
}
if(strncmp(&cmd,"T",1) == 0)
{
if(sscanf(recBuff,"%c,%[^\n]s",&cmd,argcharT) == 2)
{
if(strncmp(argcharT,"END",3) != 0)
{
xp = 1;
Do_ShowTeam(xp,yp,argcharT);
yp = yp+3;
teams++;
}
else
{
yp=1;
}
}
}
}
}
-
May 27th, 2011, 12:19 PM
#2
Junior Member
Re: Parsing Data
Parsing data in a client/server situation tends to take a bit more work than parsing data in a normal situation. I cannot think of any way to do what you are doing with less code.
-
Jun 1st, 2011, 02:00 AM
#3
Re: Parsing Data
Thanks for taking a look. I'll leave it as it is (aka "if it's not broke then don't fix it") 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|