Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 18th, 2008, 12:36 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Parsing in C/C++

Hi Guys,

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:

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 happenning count+1 times.

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

Many thanx,
Sgies
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing XML Data from a remote site timeware XML 1 June 1st, 2006 08:25 AM
Parsing and Looping through Pipe Delimetered data stewarth XSLT 2 September 5th, 2004 03:21 AM
How to Parse - Parsing Flat File Data - Asp darinsee Classic ASP Databases 5 May 24th, 2004 04:11 PM
Parse - Parsing Flat File Data - Asp darinsee Classic ASP Basics 1 May 22nd, 2004 08:39 AM
Parse - Parsing Flat File Data - Asp darinsee Classic ASP Components 1 May 22nd, 2004 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.