sprintf(str,"%s",str1);
sprintf(str,"%S",str1);
%s,%S这两个有什么不同吗?

解决方案 »

  1.   

    有一段程序,就采用sprintf(str,"%S",str1);这种写法,我把它改成了sprintf(str,"%s",str1);结果不能用了,str得到的结果不对了。难道%s,%S,大小写不同,得到的结果也不同吗?
      

  2.   

    %s String  When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached. %S String When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached. 
      

  3.   

    Type Meaning Default 
    c, C The precision has no effect. Character is printed. 
    d, i, u, o, x, X The precision specifies the minimum number of digits to be printed. If the number of digits in the argument is less than precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds precision. Default precision is 1. 
    e, E The precision specifies the number of digits to be printed after the decimal point. The last printed digit is rounded. Default precision is 6; if precision is 0 or the period (.) appears without a number following it, no decimal point is printed.  
    f  The precision value specifies the number of digits after the decimal point. If a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.  Default precision is 6; if precision is 0, or if the period (.) appears without a number following it, no decimal point is printed. 
    g, G The precision specifies the maximum number of significant digits printed. Six significant digits are printed, with any trailing zeros truncated. 
    s, S The precision specifies the maximum number of characters to be printed. Characters in excess of precision are not printed. Characters are printed until a null character is encountered 
      

  4.   

    我用的是sprintf出来的结果是?
    我自己试试吧
      

  5.   

    int MultiByteToWideChar(
      UINT CodePage,         // code page
      DWORD dwFlags,         // character-type options
      LPCSTR lpMultiByteStr, // string to map
      int cbMultiByte,       // number of bytes in string
      LPWSTR lpWideCharStr,  // wide-character buffer
      int cchWideChar        // size of buffer
    );
      

  6.   

    支持 lphlord(lphlord) 的解釋,在msdn上有解釋的,主要是在UNICODE和非UNICODE兩种情況下處理的結果不同  ^_^
      

  7.   

    它的解释有点模糊。它只说明了printf 和wprintf,别的呢?
    sprintf,strcpy,TRACE()等。其实大家试一下就可以了。这个问题还是挺麻烦的。