scanf_s i scanf

poruka: 6
|
čitano: 1.885
|
moderatori: Lazarus Long, XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
14 godina
neaktivan
offline
scanfovi
koja je razlika?za scanf u vsu dobivam upozorenja o nesigurnosti...
<<Karlovačko>>
Moj PC  
0 0 hvala 0
16 godina
neaktivan
offline
RE: scanfovi

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. 

 

Poruka je uređivana zadnji put sub 16.10.2010 21:41 (Orinem).
16 godina
neaktivan
offline
RE: scanfovi

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 :)

 

Private
16 godina
neaktivan
offline
RE: scanfovi
Private kaže...

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 

 

16 godina
neaktivan
offline
RE: scanfovi
yep :)))
Private
14 godina
neaktivan
offline
scanf_s i scanf
lol
Hvala :D
<<Karlovačko>>
Moj PC  
0 0 hvala 0
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice