help

Hi guys. Can u please help a beginner to understand, what is the difference between putchar and printf? And what is fgets? Ive seen people use fgets for strings inputted by user. What similarities does it have with scanf?
Included from <cstdio>:
fgets (http://cplusplus.com/reference/cstdio/fgets/): Used to read a string from a file object.

scanf (http://cplusplus.com/reference/cstdio/scanf/): Used to read formatted data from stdin.

putchar (http://cplusplus.com/reference/cstdio/putchar/): Used to write a character to stdout.

printf (http://cplusplus.com/reference/cstdio/printf/): Used to write formatted data to stdout.

Essentially, the f versions are formatted, meaning that you can specify widths of the strings, the number of floating points in a float or double, etc. Being unfamiliar with the C I/O, I'm not positive, but it does look like putchar doesn't support any style of strings, it only supports type casting chars and direct int values.

The same can't be said about fgets though, as it reads a string from a file object. This can't be used with stdin, I don't believe, but will effectively read the first line from a file.
Topic archived. No new replies allowed.