Results 1 to 3 of 3

Thread: [RESOLVED] Parsing Data

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Resolved [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;
    				}
    			}
    		}
    	}	
    }

  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    23

    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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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
  •  



Click Here to Expand Forum to Full Width