A few questions


1 reply [Last post]
Sirius
Sirius's picture
Offline
Joined: 2012-07-17
Points: 0

Hey everybody!

Just a few quick questions:

-what is the difference between the scanf function and the fgets function?

-what is the difference between the printf function and the sprintf function?

-what is the difference between the malloc function and the calloc function?

-what is feof, how do I use it?

-what is HINSTANCE (I know it's a handle, but what does It do)?

Thanks in advance!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
LoveCats
LoveCats's picture
Offline
W007! I watched 10 vids!
Joined: 2011-06-25
Points: 10

Watch the videos. All your answers are given in there.

 

- scanf & fgets are both used for taking user input, but fgets is considered to be more safe because you can specifiy the size of the data that can be accepted. Using scanf doesn't provide limitations on how much data the user can enter thus exposing your program to buffer overflow vulnerabilities.

- printf will send the data to output buffer to be displayed on the screen while sprintf will move the formatted string into the variable(array) specified as destination.

- malloc is used to allocated dynamic memory for a single variable while calloc is used to allocate memory for array.

- EOF is End Of File character that signifies the position where the file contents are over. feof is the function which returns true when EOF character is encountered in the file and is used as a signal to stop reading the file. For usage, I strongly recommend you view the File IO video. It must be covered there.

- HINSTANCE is a handle to a another executable where the resource (in which you're interested) is located.