home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list20_2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-16  |  392 b   |  21 lines

  1.  /* Demonstrates calloc(). */
  2.  
  3.  #include <stdlib.h>
  4.  #include <stdio.h>
  5.  
  6.  main()
  7.  {
  8.      unsigned num;
  9.      int *ptr;
  10.  
  11.      printf("Enter the number of type int to allocate: ");
  12.      scanf("%d", &num);
  13.  
  14.      ptr = calloc(num, sizeof(int));
  15.  
  16.      if (ptr != NULL)
  17.          puts("Memory allocation was successful.");
  18.      else
  19.          puts("Memory allocation failed.");
  20.  }
  21.