ILE C/C++ Programmer's Guide

Checking the Return Value of a Function

Many C and C++ run-time library functions have a return value associated with them for error-checking purposes. For example:

For information about the ILE C/C++ function return values, see ILE C/C++ Run-Time Library Functions.

To verify that each run-time library function has completed successfully, a program should check the function return values.

Example:

The following figure shows how to check the return value of the fopen() function.

Figure 160. ILE C Source to Check for the Return Value of fopen()




#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
if (( fp = fopen ( "MYLIB/QCSRC(TEST)", "ab" )) == NULL )
{
printf ("Cannot open file QCSRC(TEST)\n");
exit (99);
}
}


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