tr24731

Why can't I use fopen?

China☆狼群 提交于 2019-11-28 06:21:41
In the mold of a previous question I asked about the so-called safe library deprecations , I find myself similarly bemused as to why fopen() should be deprecated. The function takes two C strings, and returns a FILE* ptr, or NULL on failure. Where are the thread-safety problems / string overrun problems? Or is it something else? Thanks in advance There is an official ISO/IEC JTC1/SC22/WG14 (C Language) technical report TR24731-1 (bounds checking interfaces) and its rationale available at: http://www.open-std.org/jtc1/sc22/wg14 There is also work towards TR24731-2 (dynamic allocation functions)

Why didn't gcc implement _s functions?

北城以北 提交于 2019-11-28 00:04:14
_s functions, such as scanf_s , printf_s seems to be optional standard. MSVC has implemented these functions, but gcc hasn't. Is there specific reason for not implementing secure functions? Is scanf of gcc secure enough? The _s functions are optional ( Annex K of the C11 standard ). They're widely regarded as 'not very beneficial'. In the answers to my question Do you use the TR-24731 "safe" functions? , you can find information about where there are problems with the standard specification — such as crucial differences between the standard and Microsoft's implementation. TR 24731-1 was a

String input using C scanf_s

爱⌒轻易说出口 提交于 2019-11-27 07:10:38
问题 I've been trying to look for answer myself, but I can't find one. I want to insert a part of the programming that reads in a string like "Hello" and stores and can display it when I want, so that printf("%s", blah); produces Hello . Here's the code part that's giving me trouble char name[64]; scanf_s("%s", name); printf("Your name is %s", name); I know that printf isn't the problem; the program crashes after something is input after a prompt. Please help? 回答1: From the specification of fscanf

Is support of Annex K in C11 required for a conforming implementation?

試著忘記壹切 提交于 2019-11-27 06:07:11
问题 While answering a question that made use of some functions ( sscanf_s and sprintf_s ) that I thought were not standard C, Daniel Fischer brought to my attention that the functions in question were defined in Annex K. I understand generally that normative means it helps define the standard. But, an annex to the C Standard has traditionally been treated as informative only. Annex K is labeled as normative in the C11 Standard. It defines "safe" functions. Does this mean a compiler that doesn't

Header for scanf_s function

陌路散爱 提交于 2019-11-27 03:41:21
问题 While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s ? 回答1: scanf_s is Microsoft-specific. Header is stdio.h but not in GCC. Used to Read formatted data from the standard input stream. These versions of scanf, scanf_s, _scanf_l, wscanf, _wscanf_l have security enhancements Where as Ideone uses GCC because of this only you got undefined reference to

Why can't I use fopen?

天涯浪子 提交于 2019-11-27 01:18:10
问题 In the mold of a previous question I asked about the so-called safe library deprecations, I find myself similarly bemused as to why fopen() should be deprecated. The function takes two C strings, and returns a FILE* ptr, or NULL on failure. Where are the thread-safety problems / string overrun problems? Or is it something else? Thanks in advance 回答1: There is an official ISO/IEC JTC1/SC22/WG14 (C Language) technical report TR24731-1 (bounds checking interfaces) and its rationale available at:

error C4996: 'scanf': This function or variable may be unsafe in c programming

痞子三分冷 提交于 2019-11-26 22:18:15
问题 I have created a small application to find max number by using user-defined function with parameter. When I run it, it shows this message Error 1 error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. What do I do to resolve this? This is my code #include<stdio.h> void findtwonumber(void); void findthreenumber(void); int main() { int n; printf("Fine Maximum of two number\n

Reading a character with scanf_s

橙三吉。 提交于 2019-11-26 21:07:52
I was just messing around with C and ran into this small problem. As you can see from my output I getting '╠' this character. #include <stdio.h> int main(void) { char c; printf("Do you want to be X's or O's?\n"); scanf_s("%c", &c); printf("You chose %c\n", c); } See program output You are misusing scanf_s() . Microsoft compilers may warn you to use their secure extensions (aka c11 annex k). But, be careful if you do so. scanf_s() is not a direct replacement for scanf() . In this case you have to pass the size of the output buffer as an extra argument. char c; scanf_s("%c", &c, 1); Having to

Difference between scanf and scanf_s

老子叫甜甜 提交于 2019-11-26 16:35:48
What is the difference between scanf and scanf_s ? In the university I have been taught and I am using scanf , but at my personal computer Visual Studio keeps sending this warning. error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. And I have to change all scanf to scanf_s or the program won't build. (I am using Visual Studio 2013) ironslab It is a function that belongs specifically to the Microsoft compiler. scanf originally just reads whatever console input you type and assign it to a type of variable. If you have an array called first_name[5] and

Reading a character with scanf_s

巧了我就是萌 提交于 2019-11-26 07:49:28
问题 I was just messing around with C and ran into this small problem. As you can see from my output I getting \'╠\' this character. #include <stdio.h> int main(void) { char c; printf(\"Do you want to be X\'s or O\'s?\\n\"); scanf_s(\"%c\", &c); printf(\"You chose %c\\n\", c); } See program output 回答1: You are misusing scanf_s() . Microsoft compilers may warn you to use their secure extensions (aka c11 annex k). But, be careful if you do so. scanf_s() is not a direct replacement for scanf() . In