_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相应的格式规范转换。 该格式包括普通字符并具有窗体和功能和 printf的 format 参数相同。

这些功能的版本与 _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功能