This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:fall2018:data:projects:sln1 [2017/08/27 20:41] – external edit 127.0.0.1 | haas:fall2018:data:projects:sln1 [2018/09/06 14:20] (current) – [node library] wedge | ||
---|---|---|---|
Line 3: | Line 3: | ||
< | < | ||
</ | </ | ||
- | |||
- | ~~TOC~~ | ||
======Project: | ======Project: | ||
Line 132: | Line 130: | ||
We will use struct to package its contents. | We will use struct to package its contents. | ||
- | What is **in** the node? Again, this answer depends on our particular needs. For now, lacking any specific application, | + | What is **in** the node? Again, this answer depends on our particular needs. For now, lacking any specific application, |
The node, to make it practical and useful, also needs the ability to reference other nodes. Pointers are they key for referencing other variables (via memory address storage and dereferencing), | The node, to make it practical and useful, also needs the ability to reference other nodes. Pointers are they key for referencing other variables (via memory address storage and dereferencing), | ||
Line 142: | Line 140: | ||
<code c> | <code c> | ||
struct node { | struct node { | ||
- | char contents; | + | char info; |
- | struct node *to; | + | struct node *right; |
}; | }; | ||
</ | </ | ||
Line 151: | Line 149: | ||
<code c> | <code c> | ||
struct node { | struct node { | ||
- | char contents; | + | char info; |
- | struct node *to; | + | struct node *right; |
}; | }; | ||
typedef struct node Node; | typedef struct node Node; | ||
Line 160: | Line 158: | ||
<code c> | <code c> | ||
- | struct node *first; | + | struct node *first |
</ | </ | ||
Line 166: | Line 164: | ||
<code c> | <code c> | ||
- | Node *first; | + | Node *first |
</ | </ | ||
Line 187: | Line 185: | ||
<code c> | <code c> | ||
// to assign | // to assign | ||
- | first -> contents | + | first -> info = 12; // first is a pointer to a struct, so we use the structure pointer arrow |
// to retrieve | // to retrieve | ||
- | printf(" | + | printf(" |
- | // dealing with the next node, the 'there' pointer- set it to an initial sane value | + | // dealing with the next node, the 'right' pointer- set it to an initial sane value |
- | first -> to = NULL; | + | first -> right = NULL; |
</ | </ | ||
Line 210: | Line 208: | ||
<code c> | <code c> | ||
- | first -> to = (Node *) malloc (sizeof(Node)); | + | first -> right = (Node *) malloc (sizeof(Node)); |
- | first -> to -> contents | + | first -> right -> info = 37; |
- | first -> to -> to = NULL; | + | first -> right -> right = NULL; |
</ | </ | ||
Line 222: | Line 220: | ||
Since we need to keep a placeholder on our allocated memory, **first** is intended to be a more or less immovable aspect of our list (it is our link to everything- we don't want to adjust it unless we absolutely need to). | Since we need to keep a placeholder on our allocated memory, **first** is intended to be a more or less immovable aspect of our list (it is our link to everything- we don't want to adjust it unless we absolutely need to). | ||
- | You may be noticing the potential for some very long code about to happen (what if we wanted to add a third node... those there' | + | You may be noticing the potential for some very long code about to happen (what if we wanted to add a third node... those there' |
Here is that same node construction logic, redone using an additional **tmp** node pointer, and also adding in a third node (containing the value 8): | Here is that same node construction logic, redone using an additional **tmp** node pointer, and also adding in a third node (containing the value 8): | ||
< | < | ||
- | Node *first, *tmp = NULL; | + | Node *first |
first = (Node *) malloc (sizeof(Node)); | first = (Node *) malloc (sizeof(Node)); | ||
tmp = first; | tmp = first; | ||
- | tmp -> contents | + | tmp -> info = 12; |
- | tmp -> to = NULL; | + | tmp -> right = NULL; |
- | tmp -> to = (Node *) malloc (sizeof(Node)); | + | tmp -> right = (Node *) malloc (sizeof(Node)); |
- | tmp = tmp -> to; | + | tmp = tmp -> right; |
- | tmp -> contents | + | tmp -> info = 37; |
- | tmp -> to = NULL; | + | tmp -> right = NULL; |
- | tmp -> to = (Node *) malloc (sizeof(Node)); | + | tmp -> right = (Node *) malloc (sizeof(Node)); |
- | tmp = tmp -> to; | + | tmp = tmp -> right; |
- | tmp -> contents | + | tmp -> info = 8; |
- | tmp -> to = NULL; | + | tmp -> right = NULL; |
</ | </ | ||
Line 259: | Line 257: | ||
<cli> | <cli> | ||
lab46: | lab46: | ||
- | make: Entering directory '/ | + | make: Entering directory '/ |
- | Commencing copy process for fall2017 | + | Commencing copy process for SEMESTER |
-> Creating project sln1 directory tree ... OK | -> Creating project sln1 directory tree ... OK | ||
-> Copying sln1 project files ... OK | -> Copying sln1 project files ... OK | ||
Line 268: | Line 266: | ||
*** Copy Complete! You may now switch to the '/ | *** Copy Complete! You may now switch to the '/ | ||
- | make: Leaving directory '/ | + | make: Leaving directory '/ |
lab46: | lab46: | ||
</ | </ | ||
Line 284: | Line 282: | ||
**NOTE:** If you move **sln1** to a different directory, you **MUST** retain the **sln1** name for the directory-- there' | **NOTE:** If you move **sln1** to a different directory, you **MUST** retain the **sln1** name for the directory-- there' | ||
+ | |||
====Overview==== | ====Overview==== | ||
You'll see various files and directories located here (one regular file, **Makefile**, | You'll see various files and directories located here (one regular file, **Makefile**, | ||
Line 399: | Line 398: | ||
As such, it is most advisable to have completed work on **sln1** and submitted it before upgrading to the **sll0** project, so any work you've done will be immediately available to build upon in the next project (the projects will be comprehensive to one another-- **sll0** will rely on work completed in **sln1**, **sll1** (the project following **sll0**) will rely on the work done in **sll0**, etc.). | As such, it is most advisable to have completed work on **sln1** and submitted it before upgrading to the **sll0** project, so any work you've done will be immediately available to build upon in the next project (the projects will be comprehensive to one another-- **sll0** will rely on work completed in **sln1**, **sll1** (the project following **sll0**) will rely on the work done in **sll0**, etc.). | ||
+ | |||
====error reporting==== | ====error reporting==== | ||
To facilitate debugging and correction of errors and warnings in your code at compile time, such compiler messages will be redirected to a text file called **errors** in the base of the project directory. | To facilitate debugging and correction of errors and warnings in your code at compile time, such compiler messages will be redirected to a text file called **errors** in the base of the project directory. | ||
Line 405: | Line 405: | ||
With each new project build, this file is overwritten, | With each new project build, this file is overwritten, | ||
+ | |||
=====Project Task===== | =====Project Task===== | ||
Line 445: | Line 446: | ||
This is your API for the node library. In order to use the node library three things need to happen: | This is your API for the node library. In order to use the node library three things need to happen: | ||
- | * you must **#include " | + | * you must **#include " |
* you must link against **lib/ | * you must link against **lib/ | ||
* you must call the functions providing the appropriate arguments and handling the return values | * you must call the functions providing the appropriate arguments and handling the return values | ||
Line 456: | Line 457: | ||
Again, same details apply here, only the Makefile system automates the library linking. All we have to do is **# | Again, same details apply here, only the Makefile system automates the library linking. All we have to do is **# | ||
+ | |||
====Node application programs==== | ====Node application programs==== | ||
Upon successful implementation of the node library, take a look in **app/ | Upon successful implementation of the node library, take a look in **app/ | ||
Line 619: | Line 621: | ||
=====Submission===== | =====Submission===== | ||
- | {{page> | + | {{page> |