cs-academia

A work in progress; documenting my academia => There are NO DEMOS yet, just the code

View on GitHub

Project 1

Project Description

Signature Suggestions

Inside of Main Function

You may not assume the input will be less than any set size. Thus you will need to dynamically allocated space for the array.

Dynamic Allocation

Dynamic Array Allocation allows the space in an array to change during the course of the execution of a program. In C, this requires the use of the malloc() function. To dynamically allocate space for 100 integers, the malloc() code would be as follows:

int *darr;
int size = 100;
darr = (int*) malloc ( size* sizeof(int) );

This array can only hold 100 integers and it not really dynamic. To make it truly dynamic, we need to grow the array when we try to put more values into it than can be held by its current size. The following code will double the size of the array:

int *temp;
temp = (int*) malloc ( size * 2 * sizeof(int) );
int i;
for(i = 0; i < size; i++)
    temp[i] = darr[i];
free (darr);
darr = temp;
size = size * 2;

Redirection of Input and Output to Test Your Program

To help test your program, the use of redirection of standard input from a text file is a good idea for this project. Redirection is done at the command line using the less than and greater than signs. Redirection of both input and output can be done; however, for this project, you may only want to use redirection of input.

Note that the code inside of your program will still read from standard input. Redirection is information given to the Operating System at the command prompt. The Operating Systemthen “redirects” a standard input read operation away from the keyboard and to the specified file while the program is running.

Project Structure

This is to be developed in one stage, procedurally. There are 2 files being provided to us:

Restrictions for this Project

Must use dynamic allocation to store input => do not assume size via hardcoding integer sizes.

My Solution in Action

Project 1 in Action!

I have a Makefile for quicker compilation, and then we run the executable (v1). Makefile is written to support general compilation of most .c files, so I will reuse it throughout projects, making updates to it ocassionally.