•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 375,205 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,356 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 312 | Replies: 2
![]() |
fgets reads a single line of characters, but fread reads a block of unidentified objects. fgets uses '\n' as a delimiter, but fread doesn't inspect any of the objects so it relies on a limit of the number of objects. If you're using fread to read string data, the only two significant differences are:
- fgets terminates the string with '\0', but fread does not
- fgets uses '\n' as a delimiter as well as an upper limit, but fread only uses an upper limit
Subtlety is the art of saying what you think and getting out of the way before it is understood.
"fgets" is essentially a simplified version of "fread".
"fgets" is good for (and should only be used for) reading character strings from an input stream, be it a file or the stdin device.
"fread" is suited for any data type, such as binary (hex) data. it gives you more rope to hang yourself with, so if you're just wanting to read ascii text, stick with "fgets"
http://www.cplusplus.com/reference/c...dio/fread.html
http://www.cplusplus.com/reference/c...dio/fgets.html
"fgets" is good for (and should only be used for) reading character strings from an input stream, be it a file or the stdin device.
"fread" is suited for any data type, such as binary (hex) data. it gives you more rope to hang yourself with, so if you're just wanting to read ascii text, stick with "fgets"
http://www.cplusplus.com/reference/c...dio/fread.html
http://www.cplusplus.com/reference/c...dio/fgets.html
I drink your milkshake.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Other Threads in the C Forum
- Previous Thread: Algorithm Verification help please.
- Next Thread: Hiding Invisible charactors in Visual Studio 2005


Linear Mode