相关疑难解决方法(0)

为什么获取功能如此危险以至于不应该使用它?

当我尝试编译使用gets()GCC函数的C代码时,

我明白了

警告:

(.text + 0x34):警告:`gets'函数很危险,不应该使用.

我记得这与堆栈保护和安全性有关,但我不确定为什么?

有人可以帮我删除这个警告并解释为什么会有这样的使用警告gets()

如果gets()是如此危险,为什么我们不能删除它?

c gets fgets buffer-overflow

210
推荐指数
9
解决办法
14万
查看次数

这个printf技巧是如何工作的

取自这里:

printf("%d", printf("%*s%*s",a,"\r",b,"\r") );

将打印a + b的结果.

它究竟如何运作?

c printf

5
推荐指数
1
解决办法
145
查看次数

如何使用 sprintf 格式化浮点数,其中精度可能会有所不同

我必须打印一个浮点值,但是在编译时不知道精度。所以这个参数必须作为参数传递。这是如何实现的。在 windows 中,使用 CString,格式函数有助于实现这一点。如何在没有 CString 的情况下实现这一点。代码:

int main()
{

   /* This below code segment works fine.*/
   char str[80];
   sprintf(str, "Value of Pi = %.3f", 3.147758);
   std::cout << str << std::endl; //Prints "Value of Pi = 3.148"

   /* When the precision may vary, henc It needs to be printed required on that.*/
   char str2[80];
   std::string temp = "%.3f";   //This is required as the precision may change. 
                                    // i.e I may have 4 instead 3 decimal points.
   sprintf(str2, "Value = %s", temp, …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
8874
查看次数

sprintf中的奇怪符号

我在C代码中有以下定义:

#define set_str(r,s) sprintf(r, "%-.*s", (int)sizeof(r)-1,s)
Run Code Online (Sandbox Code Playgroud)

我尝试在我的代码中调用函数set_str来理解符号的含义,但它没有给出任何特殊的格式或任何东西,变量只是按原样复制.谁能告诉我这是什么意思?

c

1
推荐指数
1
解决办法
903
查看次数

标签 统计

c ×3

buffer-overflow ×1

c++ ×1

fgets ×1

gets ×1

printf ×1