APPFS
Advanced practical programming for scientists
 All Data Structures Files Functions Variables Typedefs Macros
ex1b3.c
Go to the documentation of this file.
1 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <assert.h>
13 
14 #include "nums.h"
15 
24 int main(int argc, char** argv)
25 {
26  const char* usage = "usage: %s filename\n";
27 
28  /* Check arguments, we need a filename.
29  */
30  if (argc < 2)
31  {
32  fprintf(stderr, usage, argv[0]);
33  exit(EXIT_FAILURE);
34  }
35 
36  /* we assume 32 bit integers, otherwise it will not work
37  */
38  assert(sizeof(int) == 4);
39 
40  NUMS* nsp = nums_read(argv[1]);
41 
42  if (NULL == nsp)
43  return EXIT_FAILURE;
44 
45  fprintf(stderr, "Total numbers read = %zu\n", nums_used(nsp));
46 
47  nums_print(nsp);
48 
49  nums_free(nsp);
50 
51  return EXIT_SUCCESS;
52 }
Data structure to store numbers.
Definition: nums.c:19
int main(int argc, char **argv)
Program to read a file with binary positive 32 bit integers, sort the numbers and print them sorted...
Definition: ex1b3.c:24
void nums_free(NUMS *nsp)
Free NUMS data structure.
Definition: nums.c:141
Appfs Exercise 1: Number storage and sorting subroutines.
NUMS * nums_read(const char *filename)
Read numbers into data structure.
Definition: nums.c:52
void nums_print(const NUMS *nsp)
Sort and print all numbers in the NUMS structure.
Definition: nums.c:166
size_t nums_used(const NUMS *nsp)
Return count of numbers in NUMS structure.
Definition: nums.c:187