User Tools

Site Tools


user:apardini:portfolio:cprogproject2

Project: SLL0 APardini

Date Set 15 February - 25 February 2015

Objectives

In this project we create various functions that are used in multiple programs. Our purpose is to make a function library that will be accessed for this and future projects.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • Functions
  • Pointers
  • Structs
  • nodes
  • stacks, queues
  • etc.

Background

This project involves producing code for the following function:

  • Unordered List Itemunit-mklist.c - unit test for mklist() library function
  • unit-displayf.c - unit test for displayf() library function
  • unit-insert.c - unit test for insert() library function
  • unit-getpos.c - unit test for getpos() library function
  • unit-setpos.c - unit test for setpos() library function

Scope

Give a general overview of your anticipated implementation of the project. Address any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation.

Attributes

State and justify the attributes you'd like to receive upon successful approval and completion of this project.

  • attribute1: why you feel your pursuit of this project will gain you this attribute
  • attribute2: why you feel your pursuit of this project will gain you this attribute
  • etc…

Procedure

Throughout the whole break i was having difficulties accessing the info and after values on the node of the (List) call. This was due to simple placement of braces and using the pointer in the right spot. Currently able to compile but when run in program something weird happens. Within my functions i didn't add in an if function that contained the statement: if( nodeCount != NULL) This is important because the rules state if list is not NULL

Code

Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within <code> </code> blocks here.

/*
 * hello.c - A sample "Hello, World!" program
 * 
 * written by NAME for COURSE on DATE
 *
 * compile with:
 *   gcc -o hello hello.c
 *
 * execute with:
 *   ./hello
 */
 
#include <stdio.h>
 
#include <stdio.h>
#include "node.h"
 
int main()
{
        char data[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7 };
        int i;
 
        fprintf(stdout, "Array: ");
 
        //This for loop prints the array to the screen
        for(i = 0; i < 14; i++)
 
        fprintf(stdout, "%hhd ", *(data+i));
        fprintf(stdout, "\n");
 
        struct node *first;                             //Declares the nodes to be made from the function
        struct node *nodeMark;
        i = 0;                                          //Sets loop counter to 0
 
        first = mknode(data[i]);                        //Creates the first initial node before the loop is run
 
        nodeMark = first;                               //nodeMark is what is used to run through the array to print. Here it is set to the first value of the array
        //This for loop loads the array into a list
        for(i = 1; i < 14; i++)
        {
        nodeMark -> after = mknode(data[i]);
        nodeMark = nodeMark -> after;                   //This loop creates the nodes from the array beggening from the second eleent of the array. not set to 0
        }
 
        nodeMark = first;                               //Important to set the nodeMark to first before printinh
        fprintf(stdout, "list:" );
 
        while (nodeMark != NULL)
        {
                fprintf(stdout,"%hhd ", nodeMark -> info);      //Node info is set to print nodeMark -> after will keeping printing the node until the element = null
                nodeMark = nodeMark -> after;
        }
 
        return(0);
}
 
 
 
 
#include <stdio.h>
#include "node.h"
 
int main()
{
        Node *tmp, *tmp2,*first;
        char input;
 
        first = tmp          = tmp2 = (Node *) malloc (sizeof(Node)*1);
        tmp -> info = 0;
        tmp -> after  = NULL;
 
        fprintf(stdout, "Enter a info (-1 to quit): ");
        fscanf(stdin, "%hhd", &input);
 
        while (input != -1)
        {
                tmp2 -> info = input;
 
                tmp2 -> after = (Node *) malloc (sizeof(Node)*1);
                tmp2 -> after -> info = 0;
                tmp2 -> after -> after  = NULL;
 
                fprintf(stdout, "Enter a info (-1 to quit): ");
                fscanf(stdin, "%hhd", &input);
 
                if (input == -1)
                {
                        free(tmp2 -> after);
                        tmp2 -> after = NULL;
                }
                else
                        tmp2 = tmp2 -> after;
        }
        // Added print section with do loop
        tmp2 = first;                           //important to set tmp to first to begin print process
        fprintf(stdout,"list:");
        while (tmp2 != NULL)
        {
                fprintf(stdout,"%hhd ", tmp2 -> info);          //tmp2 info is displayed. The next line sets tmp to the address after inorder to repeat printing
                tmp2 = tmp2 -> after;
        }
 
        // Added print section with do loop
        tmp2 = first;                           //important to set tmp to first to begin print process
        fprintf(stdout,"list:");
        while (tmp2 != NULL)
        {
                fprintf(stdout,"%hhd ", tmp2 -> info);          //tmp2 info is displayed. The next line sets tmp to the address after inorder to repeat printing
                tmp2 = tmp2 -> after;
        }
 
 
 
 
        return(0);
}

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

lab46:~/src/cprog$ ./hello
Hello, World!
lab46:~/src/cprog$ 

Reflection

Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?

References

In performing this project, the following resources were referenced:

  • URL1
  • URL2
  • URL3 (provides useful information on topic)
  • URL4

Generally, state where you got informative and useful information to help you accomplish this project when you originally worked on it (from Google, other wiki documents on the Lab46 wiki, etc.)

user/apardini/portfolio/cprogproject2.txt · Last modified: 2015/02/25 15:17 by apardini