Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

test_read_file.c

This file shows how to use the function read_file().

#include <stdio.h>
#include "files.h"

int main (int argc, char *argv[])
{
  int   cr;
  char  *buff;

  if (argc != 2)
  {
    fprintf (stderr, "\nUsage: read_file.test <file name>\n");
    return 1;
  }

  cr = read_file (argv[1], &buff);

  if (cr == FILES_UTIL_MALLOC_ERR)
  {
    fprintf (stderr, "\nMalloc error!\n");
    return 1;
  }

  if (cr == FILES_UTIL_READ_ERR)
  {
    fprintf (stderr, "\nRead error!\n");
    return 1;
  }

  if (cr == FILES_UTIL_OPEN_ERR)
  {
    fprintf (stderr, "\nOpen error!\n");
    return 1;
  }

  fprintf (stdout, "\n\n%d bytes read:\n\n%s\n\n", cr, buff);

  free (buff);
  return 0;
}

Generated on Thu Apr 3 16:23:41 2003 for Common_C_libraries by doxygen1.3-rc1