ILE C/C++ Programmer's Guide

ISO C Record I/O

If you use an ISO C record I/O in your program, you must specify type = record in the open mode parameter of fopen() when you open a file, and you must use the FILE data type. The following figure provides an example.

Figure 40. Example: Using ISO C Record I/O




#include <stdio.h>
#define MAX_LEN 80
int main(void)
{
FILE *fp;
int len;
char buf[MAX_LEN + 1];
fp = fopen("MY_LIB/MY_FILE", "rb, type = record");
while ((len = fread(buf, 1, MAX_LEN, fp)) != 0)
{
buf[len] = '\0';
printf("%s\n", buf);
}
fclose(fp);
return 0;
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]