sprintf报错,sprintf sprintf_s

http://www.itjxue.com  2023-01-24 05:43  来源:未知  点击次数: 

sprintf 输出中文乱码求助!

Char使用的是ASCII的码值表,

每个Byte表示一个字符,

中文是没有办法用ASCII来表示的。

所以你这里无法正常输出,问号是输出报错。

要输出中文,只能用Unicode的库。

那也不是Char类型可以处理的了。

c++编程,sprintf这个错误该怎么改?上次编译时没报错啊。

嗯,应该是少了头文件。

sprintf

功能

把格式化的数据写入某个字符串缓冲区。

头文件

stdio.h

原型

int sprintf( char *buffer, const char *format, [ argument] … );

参数列表

buffer:char型指针,指向将要写入的字符串的缓冲区。

format:格式化字符串。

[argument]...:可选参数,可以是任何类型的数据。

返回值:字符串长度(strlen)

怎么解决c51混合编程时调用printf报错?sprintf也会

C标准没有输出二进制的,不过用itoa()可以实现到二进的转换。

1、在C语言程序中,可以使用标准库函数中printf()来向屏幕输出信息,或者使用sprintf()向缓冲区输出信息。对整数而言,可以使用%d、%o、%x(或%X)输出十进制形式、八进制、十六进制形式,但貌似缺乏二进制形式。

2、解决方式有两种,一种是利用Windows提供的itoa()函数,另一种自行设计一个新的函数:

代码一:

/** Test.h */

#pragma once

#ifndef Test_H

#define Test_H

/** use itoa() to print integers in the form of binary

* @param[in] n the integer to print

* @return void

*/

void printBinaryByItoa(unsigned int n);

代码二:

/** Test.c */

#include stdio.h

#include stdlib.h

void printBinaryByItoa(unsigned int n)

{

unsigned char data[33];

_itoa_s(n, data, 33, 2);

printf("%sb\n", data);

}

void printBinary(unsigned int n, unsigned char separator, unsigned char needPrefixZeros)

{

unsigned int i = 0;

unsigned int mask = 0; /* the mask code to get each bit of n */

unsigned char data[40]; /* the buffer to store the bits of n in the form of characters */

unsigned int index = 0; /* used to access data[] */

unsigned int start = 0; /* to point out where and when to store bits of n */

data[39] = '\0';

关于sprintf的问题,很菜的。

sprintf(s,"%d",123);

sprintf()的第一个参数是缓存区。被格式化的串被写入此缓存需。

a是整型,不是缓存区。s可以

keil c51中sprintf一使用就报错?

DATA区的RAM使用太多了,错误信息说DATA溢出了。

113个字节就溢出,看样子,你用的是89C51,你把使用的芯片改成89C52就可以了。

关于sprintf(s,"%d",123);

char *s *s里面的内容是不能修改的 它是字符串常量,存放在静态存储区

所以会报错的 内存非法访问

(责任编辑:IT教学网)

更多

相关mac苹果系统文章

推荐mac苹果系统文章