GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Feb-2008, 10:33
sgies sgies is offline
New Member
 
Join Date: Feb 2008
Posts: 1
sgies is on a distinguished road

Data Parsing in C/C++


I am looking for a solution of parsing data in C language, I have attached the code below with some comments in it. What actually I am looking for not to call the sscanf function with the number data is available (In this it is 3) as it is random and can be anywhere between 0 to 9.

Code:

CPP / C++ / C Code:
main()
{
    char buffer[500] = "DATA:  3,43,56,32f402,44,57,32f403,45,58,32f404";
    char *buf = buffer;
    int count;
    sscanf(buffer, "DATA: %d", &count); //First Value is Count, get it in a variable.
    printf("Count - %d\n", count);
    buf+=8; //strlen("DATA: 3,") = 8
    for(int c = 0; c < count; c++)
    {
        int a1, a2, a3;
        sscanf(buf, "%d,%d,%x", &a1, &a2, &a3);
        printf("%d,%d,%x\n", a1, a2, a3);
        buf+=13;//strlen("43,56,32f402,");
    }
    return 0;
}

Can some one suggest any alternate solution with less number of calls to sscanf, in this sample code it is happening count+1 times.

If anyone can point me to C++ library routine will be helpful as well.

Many thanks,
Sgies
Last edited by admin : 18-Feb-2008 at 16:18. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak when nothing is happening... How can I even debug this ? Algar MS Visual C++ / MFC Forum 10 19-Nov-2007 08:17
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
Strange C++ code memory leakage problem gaoanyu C++ Forum 7 04-Nov-2005 09:09
problem parsing data from a file in C brett C Programming Language 6 25-Apr-2005 11:34
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:06.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.