- +/- sve poruke
- ravni prikaz
- starije poruke gore
Pa sam kompajler ti je da odgovor :P scanf_s je sigurniji od scanf
Da nepisen bzvz evo copy paste
char name[10]; //declares an array that can hold 10 characters
scanf("%s", name); //gets a string from the user and puts it in name
this will work fine if the user's name is rick or something smaller than 9 characters (9 because the last character is a terminator), but if the user's name is 10 or more characters, scanf starts writing into memory that doesn't belong to name. C won't catch this or warn you, so you won't find out until something else tries to use that memory and your program crashes.
Because this is such a common issue, scanf_s checks that the user input will fit in the given memory space, so many problems are avoided.
Navod :
"Basically scanf_s is more secure. C does no type checking for you, so when you use scanf, C doesn't make sure that what the user inputs will fit in the variable that you've designated. For example, if you use this code,
char name[10]; //declares an array that can hold 10 characters
scanf("%s", name); //gets a string from the user and puts it in name
this will work fine if the user's name is rick or something smaller than 9 characters (9 because the last character is a terminator), but if the user's name is 10 or more characters, scanf starts writing into memory that doesn't belong to name. C won't catch this or warn you, so you won't find out until something else tries to use that memory and your program crashes.
Because this is such a common issue, scanf_s checks that the user input will fit in the given memory space, so many problems are avoided.
"
Eto zašto :)
Navod :
"Basically scanf_s is more secure. C does no type checking for you, so when you use scanf, C doesn't make sure that what the user inputs will fit in the variable that you've designated. For example, if you use this code,
char name[10]; //declares an array that can hold 10 characters
scanf("%s", name); //gets a string from the user and puts it in name
this will work fine if the user's name is rick or something smaller than 9 characters (9 because the last character is a terminator), but if the user's name is 10 or more characters, scanf starts writing into memory that doesn't belong to name. C won't catch this or warn you, so you won't find out until something else tries to use that memory and your program crashes.
Because this is such a common issue, scanf_s checks that the user input will fit in the given memory space, so many problems are avoided.
"
Eto zašto :)
DOk san ja edit posta si isti tekst
Hvala :D
