What is the difference between File and Struct in C?

Hello. I am currently on ex17 and I notice the use of ‘FILE’ and ‘struct’. In this particular example, the first place I see this is

Struct Connectio n{
FILE *file;
Struct Database *db;

Can anyone help me understand the difference?

This should have been covered earlier, shouldn’t it?

FILE* is a pointer to a stream handle, which is the type of object that all the I/O functions use to interact with input/output streams. stdout is a FILE*, just like the things you get by any call to fopen. See also here.

A struct is the compound type in C, comparable to objects in JavaScript and dictionaries in Python, with the big difference that a struct always contains a predefined number of things of a predefined type.

Does that help?

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.