Some array functions
/** Driver = 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 **/
#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 - You may end
up modifying the following input subprogram to fit the needs of a
specific application. For example, you may want to ask the user
if he/she wants to continue rather than simply using the stopping
value. However, the basic subprogram will change very little.
**/
void fill_1d_int_part(array, low, high, actual and stopping value)
/** Source file = array_int.c **/
#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]);
}
/** here is the pseudocode partially filling an array
you need the array, the low and high index, actual and the stopping value
as parameters. The stopping value parameter may be used or not depending
on the program needs.
**/
void fill_1d_int_part( parameters go here )
{
int temp;
int i = low;
loop
{
get a value from the user and put it in temp
if temp is not the stopping value
{
put the value of temp into array[i]
increment i
}
}
until array is full or the stopping value has been entered
*actual = i - 1;
/* the following output is not mandatory for the subprogram. Could
easily be left out since the calling subprogram can easily find
out that the array is full (actual == MAX_SIZE - 1)
*/
if the array is full
printf("\nArray is full - no more input permitted.\n");
}