sscanf 怎么解析 "a1do&123456" 到 buf1=a1do 和 buf2=123456被弄晕了, 我怎么写只能得到前面一节.谢谢大家!

解决方案 »

  1.   

    用strchr定位 '&',然后在分左右拷贝不是更好    sscanf直接解析好象不行吧 
      

  2.   


    我是想学学sscanf ,我之前是用的 Find 类似你的方法.
      

  3.   

    无法实现
    sscanf不是用在这种场合
      

  4.   

    sscanf不能解析你这种类型的字符串,如果各个数据项之间用的是空格、逗号、分号就可以用它。你可以用CString的Find或者strchr来查找到&来分割.
      

  5.   

    sscanf 只能处理它认可的分隔符,不能你自定义等,自己查找吧
      

  6.   

    可以实现
    char temp[20];
    int a;
    _stscanf(_T("a1do&123456"), _T("%[^&]&%d"), temp, &a);
    CString str;
    str.Format(_T("%s   %d"), temp, a);
    MessageBox(str);
      

  7.   

    是2个字符数组?
    TCHAR temp[20];
    TCHAR temp1[20];
    _stscanf(_T("a1do&123456"), _T("%[^&]&%s"), temp, temp1);
    CString str;
    str.Format(_T("%s   %s"), temp, temp1);
    MessageBox(str);
      

  8.   


    晕, 好像 temp1 2必须是TCHAR, 不能使CString 哦? 难怪我试了好久也不行
      

  9.   

    真的可以,强大,用了这么多年sscanf第一次发现还有这个特性,拜一个
    Specifier Meaning
    %dAn integer in normal decimal (that is, base-10) notation.%oAn integer in octal (base-8) notation.%xAn integer in hexadecimal (base-16) notation.%DAn integer in decimal, or (if it starts with 0) octal, or (if it starts with 0x) hexadecimal notation. Hence, sscanf("12", "%D", i), sscanf("014", "%D", i) and sscanf("0xC", "%D", i) all yield the value 12 in i.%fA floating-point number.%cThe character code of a single character.%sA string. If %s is followed by %d, %s will read any non-numerical characters. If followed by %[], %s will read any characters not present in the set in the %[]. If followed by normal text, %s will match all characters up to, but not including, the first occurrence of that text.%NsAs above, but a string of exactly N characters%[characters]A string containing any of the characters in the list characters.A minus sign can be used to give a range of values, so e. g. %[a-d] means a string consisting of any of the characters a, b and c.A ^ sign means "not", so e. g. %[^abc] means any character except a, b and c.They can be combined, so %[a-cf] means a, b, c, and f.