Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FILE data type?

Status
Not open for further replies.

aaronvegh

Technical User
Apr 12, 2001
3
Hi there,
I've got some C experience, but not a ton. I'm working on integrating a library of C code into a C project that I'm writing, but I'm stumbling on supplying a required argument because I don't have the right data type. The function signature is

static void blockPrint (FILE *fp, const BYTE *block, int blockBits, const char *tag)

It's the first argument that I'm not getting. In the example code for this function, a regular string is being sent to this function (i.e. "file.txt"), but in my code I have the file path in question supplied as a const char *. But what the heck is a var of type FILE? I can't find this anywhere in Google or the C docs.

I'm guessing this is a total n00b question, but a little help would... uh, help.

Thanks!
Aaron.
 
Ah, good search! That did it. For the kids at home, the FILE type actually requires a connected resource via the fopen() call. So you can't simply declare a variable of type FILE; you have to then use it to open a file.

FILE *realFile = fopen(theFile, "r");
blockPrint(realFile, block, BITSPERBLOCK, "PT");

Cheers!
Aaron.
 
Strictly speaking, in C the FILE type is a library defined (in stdio.h header) type alias (see typedef keyword). No need to use FILE type as such, only FILE* (pointer to FILE) type. It's (one of;) C language funny idioms.
As usually, FILE type alias denotes library defined structure, but don't use its members directly (it's implementation dependent entity).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top