_scprintf、 _scprintf_l、 _scwprintf、 _scwprintf_l

傳回格式化字串中的字元數。

int _scprintf(
   const char *format [,
   argument] ... 
);
int _scprintf_l(
   const char *format,
   locale_t locale [,
   argument] ... 
);
int _scwprintf(
   const wchar_t *format [,
   argument] ... 
);
int _scwprintf_l(
   const wchar_t *format,
   locale_t locale [,
   argument] ... 
);

參數

  • format
    控制項的格式字串。

  • argument
    選擇性的引數。

  • locale
    若要使用地區設定。

如需詳細資訊,請參閱格式規格

傳回值

傳回如果該字串一樣列印或傳送到檔案或使用指定的格式代碼的緩衝區,則會產生的字元數。傳回的值不包含結束的 null 字元。_scwprintf寬字元來執行相同的功能。

如果format是NULL指標,不正確的參數處理常式會叫用,如所述參數驗證。如果執行,則允許繼續執行,這些函數會傳回-1,並設定errno到EINVAL。

如需這些和其他錯誤碼資訊,請參閱 _doserrno、 errno、 _sys_errlist,以及 _sys_nerr

備註

每個argument (如果有的話) 會轉換成對應的格式規格,以根據format。一般字元所組成的格式,與具有相同的表單,並作為format引數的 printf

使用這些函式的版本_l尾碼完全相同,不同之處在於它們使用傳遞中而不是目前執行緒的地區設定的地區設定參數。

安全性注意事項安全性提示

請確定format不是使用者定義的字串。

泛用文字常式對應

Tchar.h 常式

_Unicode 之後,未定義的 _MBCS

定義的 _MBCS

定義 _unicode 之後

_sctprintf

_scprintf

_scprintf

_scwprintf

_sctprintf_l

_scprintf_l

_scprintf_l

_scwprintf_l

需求

常式

所需的標頭

_scprintf, _scprintf_l

<stdio.h>

_scwprintf, _scwprintf_l

<stdio.h> 或者 <wchar.h>

如需相容性資訊,請參閱相容性在簡介中。

範例

// crt__scprintf.c

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <math.h>
#include <malloc.h>

int main( void )
{
   int count;
   int size;
   char *s = NULL;

   count = _scprintf( "The value of Pi is calculated to be %f.\n",
                      M_PI);

   size = count + 1; // the string will need one more char for the null terminator
   s = malloc(sizeof(char) * size);
   sprintf_s(s, size, "The value of Pi is calculated to be %f.\n",
                      M_PI);
   printf("The length of the following string will be %i.\n", count);
   printf("%s", s);
   free( s );
}
  
  

請參閱

參考

資料流 I/O

fprintf、 _fprintf_l、 fwprintf、 _fwprintf_l

printf、 _printf_l、 wprintf、 _wprintf_l

scanf、 _scanf_l、 wscanf、 _wscanf_l

sscanf、 _sscanf_l、 swscanf、 _swscanf_l

vprintf 函式