Tag: tr24731

使用C scanf_s输入字符串

我一直在努力寻找答案,但我找不到答案。 我想插入一个读取字符串的部分,如“Hello”字符串并存储并可以在需要时显示它,以便printf(“%s”, blah); 产生Hello 。 这是给我带来麻烦的代码部分 char name[64]; scanf_s(“%s”, name); printf(“Your name is %s”, name); 我知道printf不是问题; 在提示输入某些内容后程序崩溃。 请帮忙?

对memcpy_s的未定义引用

我正在尝试修复对memcpy_s()错误的未定义引用。 我在我的文件中包含了string.h , memcpy()函数运行正常,我也尝试过包含memory.h 。 我在x64 Windows 7上并使用gcc 4.8.1进行编译。 #include #include #include void doMemCopy(char* buf, size_t buf_size, char* in, int chr) { memcpy_s(buf, buf_size, in, chr); } buf内存已在main函数中分配,该函数调用doMemCpy(buf, 64, in, bytes) 。 in是从标准输入读取的字符串 来自cmd终端的确切错误: 未定义引用“memcpy_s”collect2.exe:错误:ld返回1退出状态

sprintf_s缓冲区太小

以下代码导致错误并杀死我的应用程序。 这是有意义的,因为缓冲区只有10个字节长,文本长度为22个字节(缓冲区溢出)。 char buffer[10]; int length = sprintf_s( buffer, 10, “1234567890.1234567890.” ); 我如何捕获此错误,以便我可以报告它而不是崩溃我的应用程序? 编辑: 阅读下面的评论后,我选择_snprintf_s。 如果它返回-1值,则缓冲区未更新。 length = _snprintf_s( buffer, 10, 9, “123456789” ); printf( “1) Length=%d\n”, length ); // Length == 9 length = _snprintf_s( buffer, 10, 9, “1234567890.1234567890.” ); printf( “2) Length=%d\n”, length ); // Length == -1 length = _snprintf_s( buffer, 10, […]

我遇到多个字符和scanf_s()的问题

我正在尝试使用scanf_s()来读取多个值,但每次运行程序时,我都会得到 实验室中0x592AD6AC(msvcr120d.dll)的未处理exception2.exe:0xC0000005:访问冲突写入位置0x00000000。 在弹出窗口中。 我该如何解决? float inTemp; char inUnit; char outUnit; printf(“Please enter the starting temperature with its units and the units\nyou would like to convert to (ie 74.5 FC): “); scanf_s(“%f %c %c”, &inTemp, &inUnit, &outUnit); //takes in all user input (NOT WORKING)

scanf_s函数的标头

在回答这个问题时,我在Ideone上编译了代码并得到了这个错误 implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] 是不是stdio.h是scanf_s的头?

是否有任何strcpy_s和/或TR24731-1的免费实现?

我有一个混合了C和C ++的旧项目。 它广泛使用C字符串以及strcpy , strcat , strncpy , strncat等。我发现了许多缓冲区溢出,我想使用更安全的函数,例如strcpy_s 。 MSVC包含这些function,但我需要能够在各种平台上运行的东西 – 至少是linux,osx和windows。 我知道strlcpy ,但是很多人都注意到( 例子 ),这确实不是一个改进。 那么:是否有strcpy_s , strcat_s等或整个TR24731-1免费实现? 我需要一些public domain或BSD ,但如果你知道其他许可证下的实现,请继续列出它们 – 我相信别人会受益。

错误:使用未声明的标识符’errno_t’

这是我死的简单虚拟代码: #include int main(void) { errno_t e; return 0; } 这令人惊讶地引发了这个错误: main.c:5:5: error: use of undeclared identifier ‘errno_t’ errno_t x; ^ 我开始遵循这些跟踪 :当编译器看到包含时,它将首先查看/usr/include当然我找到了errno.h文件。 实际上它除了许可证注释外还有一行,它是: #include 现在,在errno.h /usr/include/sys中,我找到了以下行: #include #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 #include #endif 在/usr/include/_types中的/usr/include/_types _errno_t.h我发现了这个: typedef int errno_t; 所以看起来,它就在那里,它是整数类型的别名,也是errno.h一部分 – 正如它应该的那样。 那为什么不包括在内呢? 为什么编译器会引发未声明的标识符错误? 提前致谢! 相关信息: Compiler: Apple LLVM version 5.1 (clang-503.0.40) (based […]

使用scanf_s读取字符

我只是乱搞C并遇到了这个小问题。 正如你从我的输出中看到的那样,我得到了’╠’这个角色。 #include “stdio.h” void main() { char c; printf(“Do you want to be X’s or O’s?\n”); scanf_s(“%c”, &c); printf(“You chose %c\n”, c); } 见程序输出

错误C4996:’scanf’:此函数或变量在c编程中可能不安全

我创建了一个小应用程序,通过使用带参数的用户定义函数来查找最大数量。 当我运行它时,它会显示此消息 错误1错误C4996:’scanf’:此函数或变量可能不安全。 请考虑使用scanf_s。 要禁用弃用,请使用_CRT_SECURE_NO_WARNINGS。 详细信息请参见在线帮助。 我该怎么做才能解决这个问题? 这是我的代码 #include void findtwonumber(void); void findthreenumber(void); int main() { int n; printf(“Fine Maximum of two number\n”); printf(“Fine Maximum of three number\n”); printf(“Choose one:”); scanf(“%d”, &n); if (n == 1) { findtwonumber(); } else if (n == 2) { findthreenumber(); } return 0; } void findtwonumber(void) { int a, […]

为什么我不能使用fopen?

在上一个问题的模型中, 我询问了所谓的安全库弃用 ,我发现自己同样感到困惑的是为什么fopen()应该被弃用。 该函数接受两个C字符串,并返回FILE * ptr,或者在失败时返回NULL。 线程安全问题/字符串溢出问题在哪里? 或者是别的什么? 提前致谢