Pointer notation with 1-D arrays
I copied this file from the previous example of array functions. I made
changes to array_int.h and array_int.c but NOT to main.c.
/** Driver = main.c **/
I have made NO changes to main.c.
**/
#include <stdio.h>
#include "array_int.h"
#include "myio_c.h"
int main(void)
{
int array[10], actual;
fill_1d_int_all(array, 0, 9);
write_1d_int(array, 0, 9);
printf("\nEnter 1 to stop");
fill_1d_int_part(array, 0, 9, &actual, 1);
printf("\nActual = %d ", actual);
write_1d_int(array, 0, actual);
printf("\nEnter 1 to stop");
fill_1d_int_part(array, actual + 1, 9, &actual, 1);
printf("\nActual = %d ", actual);
write_1d_int(array, 0, actual);
return (0);
}
/** Header file = array_int.h **/
/* The only change to this file is substituting a * for [] */
#include <stdio.h>
#include "myio_c.h"
void fill_1d_int_all(int *, int, int);
void write_1d_int(int *, int, int);
/** you have to figure out the types of the parameters below and
whether or not you need all or only part of them **/
void fill_1d_int_part(array, low, high, actual and stopping value)
/** Source file = array_int.c **/
/** I used all * notation in the function headers and pointer arithmetic
to access the arrays **/
#include "array_int.h"
void fill_1d_int_all(int *array, int low, int high)
{
int i;
for (i = low; i <= high; i++)
get_int(array + i);
}
void write_1d_int(int *array, int low, int high)
{
int i;
for (i = low; i <= high; i++)
printf("%d ", *(array + i));
}