Parsing char array to CString and int array

This is a discussion on Parsing char array to CString and int array within the C Programming forums, part of the General Programming Boards category; Hi all, I have a char buff[100] which contains "1234 ABCD 5678". I can't remember what function I used before ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    Parsing char array to CString and int array

    Hi all,

    I have a char buff[100] which contains "1234 ABCD 5678".

    I can't remember what function I used before to parse the string into
    individual variables. It was something like this:

    forgotenFunction(var1, var2, var3, buff, "%d %s %d")

    It gave me this:

    var1[4] = "1234"
    var2 = "ABCD"
    var3[4] = "5678"

    var1 and var3 are going to be an int array and var2 is a string.

    i remember something regarding parsing by using the space as an identifier?

    Any ideas? I will appreciate it.

    Thanks in advance Smile

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    sscanf() perhaps?

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    perhaps this one

    Code:
        str = ptr;
        while( sscanf(str, "%[^ ]%n", str1, &n) != -1)
        {
               if(n > 0)
                    printf("%s\n", str1);
               str += n;
               n=0;
               if(*str != ' ')
                       break;
               ++str;
        }
    ssharish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  2. cstring algorithm.. what do you think?
    By The Brain in forum C++ Programming
    Replies: 6
    Last Post: 01-26-2005, 02:54 AM
  3. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 11:23 AM
  4. Converting from CString to char
    By Dual-Catfish in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2003, 03:44 PM
  5. Converting CString to int ??
    By eko-eko in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2002, 08:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21