Discussed in class:
dynamic memory allocation syntax error logical error runtime error
Talked about the games Free cell, Forty thieves, and eight off.
TURTLE DAY!!!! “mv - command to 'move' files”
Discussed in class:
Pointers Class Chat room Review roll: flip: define: 'word' weather: 'zip' Opus Review Mercurial Repo's hg add hg push
Created/added
classroom chats made directories 'structures'
ptr.c
#include<stdio.h> #include<stdlib.h> int main( ) { int a, *b; a=12; // b=&a; fprintf( stdout, "[a] address is: 0x%X\n", &a ); fprintf( stdout, "[a] contains: %d\n", a ); // fprintf( stdout, "[a] dereferences to: %d\n", a); fprintf( stdout, "[b] address is: 0x%X\n", &b ); fprintf( stdout, "[b] contains: 0x%X\n", b ); fprintf( stdout, "[b] dereferences to: %d\n", *b); return(0); }
numberfun.c
#include<stdio.h> #include<stdlib.h> int main( ) { signed char sc=0; unsigned char uc=0; printf(" a signed char is %hhu bytes\n", sizeof(sc)); printf(" lower bound is: %hhd\n", ((unsigned char)(sc-1)/2+1)); printf(" upper bound is: %hhd\n", ((unsigned char)(sc-1)/2)); printf(" --------------\n"); printf(" an unsigned char is: %hhu bytes\n", sizeof(uc)); printf(" lower bound is: %hhu\n", uc); printf(" upper bound is: %hhu\n", uc-1); printf(" --------------\n"); return(0); }
%d - signed int %u - unsigned int %hu - half(short) unsigned int %hd - half(short) signed int %hhu - half half (short short) unsigned int %hhd - half half (short short) signed int %lu - long unsigned int %ld - long signed int
struct.c
#include <stdio.h> #include <stdlib.h> int main( ) { struct person { char *name; int age; long int id; }; typedef struct person Person; //struct person People[8]; Person People[8]; int i=0; for (i=0;i<8;i++) { printf("Enter person #%d's name:", (i+1)); People[i].name=(char*)malloc(sizeof(char)*20); scanf("%s", People[i].name); printf("Enter %'s age:", People[i].name); scanf("%d", &People[i].age); printf("Enter %s's id number:", People[i].name); scanf("%d", &People[i].id); } i=-1; while(i==-1) { printf("Look up data for person #:"); scanf( "%d", &i ); if(!((i>=0)&&(i<=7))) { printf("Invalid person #. Try again!\n"); i=-1; } } printf( "Name: %s\n", People[i].name); printf( "Age: %d\n", People[i].name); printf( "ID: %d\n", People[i].id); return(0);
TURTLE DAY!!!! “You can check your file permission with ls -l”
structnode.c
#include <stdio.h> #include <stdlib.h> struct node { int value; struct node *next; }; typedef struct node Node; int main() { int input = 0; Node *list, *tmp; list = tmp = NULL; while (input != -1) { printf("Enter a value(-1 to end):"); scanf("%d", &input); if (input != -1) { if (list == NULL) { list = tmp = (Node *) malloc(sizeof(Node)); tmp->next = NULL; list->next = NULL; } else { tmp->next = (Node *) malloc(sizeof(Node)); tmp->next->next = NULL; tmp->next->value = input; tmp = tmp->next; } } } tmp = list; while (tmp !=NULL) { printf("%d ->", tmp->value); tmp = tmp->next; } printf("NULL\n"); return (0); }
GNU nano 2.2.4 File: linkedlist_2.c #include<stdio.h> #include<stdlib.h> struct node{ int value; struct node *next; }; typedef struct node Node; int main() { int input = 0; int seeker; Node *list, *tmp, *tmp2; list = tmp = tmp2 = NULL; while( input != -1 ) { printf("Enter a value (-1 to end): "); scanf("%d", &input); if( input != -1) { if( list == NULL ) { list = tmp = (Node*)malloc(sizeof(Node)); tmp->next = NULL; list->value = input; } else { tmp->next = (Node*)malloc(sizeof(Node)); tmp->next->next = NULL; tmp->next->value = input; tmp = tmp->next; } } } tmp = tmp->next; input++; } printf("NULL\n"); //Insert into list printf("Which node would you like to insert before: "); scanf("%d", &input); tmp = list; for( seeker = 0; seeker < (input-1); seeker++ ) tmp = tmp->next; if( input==0) { printf("Enter value for new node:"); scanf("%d", &input); tmp2 = (Node*)malloc(sizeof(Node)); tmp2->value = input; tmp2->next = NULL; tmp2->next = tmp; list = tmp2; } else { printf("Enter a value to insert: "); scanf("%d", &input); tmp2 = (Node*)malloc(sizeof(Node)); tmp2->value = input; tmp2->next = tmp->next; tmp->next = tmp2; } tmp = list; input = 0; while( tmp != NULL ) { printf("[%d] %d\n", input, tmp->value); tmp = tmp->next; input++; } return(0); }
TURTLE DAY!!!!
_ .-./*) _/___/ `. U U 'You can change your file permissions with 'chmod'.'
REMOVE NODE, NOT DELETING BUT JUST MAGIC!!!
tmp=list; input<-node # to remove; for(seeker=0; seeker<(input-1); seeker++); { tmp=tmp->next; } tmp2=tmp->next; tmp->next=tmp2->next; tmp2->next=NULL; [ display list ]
TURTLE DAY!!!!
_ .-./*) _/___/ `. U U 'You can check the current directory by typing 'pwd'.'
_ .-./*) _/___/ `. U U 'You can copy files with the 'cp' command.'
WHA WHOOOOOOOOOOO!!!! First day being back from kid being sick… OMG FREEDOM!!!
WORKING ON ASSESSMENT
WORKING ON ASSESSMENT
WORKING ON ASSESSMENT
STACKS!!!!!!!!!!!!!!
Main Operations
pop() - takes the top item off the stack push() - puts an item on the top of the stack peek() - shows us the top of the stack
Pointers
top - pointer always located at top of stack
mkstack() - creates new stack
stack.h
#ifndef _STACK_H #define _STACK_H #include "dll.h" struct stack { List *data; Node *top; int size; }; typedef struct stack Stack; Node *pop(Stack*); Node *push(Stack*, Node*); Stack *mkstack(int); Node *peek(Stack*); #endif
stactops.c
#include "stack.h" Stack *mkstck(int size) { Stack *myStack; myStack=(Stack*)malloc(sizeof(Stack)); myStack->size=size; myStack->data=mklist(); myStack->top=myStack->data->end; return(myStack); }
push.c
#include "stack.h" void push ( Stack **myStack, Node *newNode ) { if((*myStack)->size<(*myStack->qty)) { (*myStack)->data=append((*myStack)->data,(*myStack)->data->end, newNode); (*myStack)->top=(*myStack)->data->end: } }
TURTLE DAY!!!!
_ .-./*) _/___/ `. U U 'You can use 'ncal' to look up the date of easter.'
lab46:/var/public/data/fall2013$
POP!!!!!!!
pop.c
include "stack.h" Node *pop(Stack **myStack) { Node *tmp; if ((*myStack)!=NULL) { tmp=getNode(&(*myStack)->data, (*myStack)->data->end); (*myStack)->top=(*myStack)->data->end; } return(tmp); }
#include "stack.h" Stack * push(Stack *myStack, Node *newNode) { if((*myStack->size <= 0) || (myStack->data->qty < myStack->size)) { (*myStack)->data = append((*myStack)->data, (*myStack)->data->e$ (*myStack)->top = (*myStack)->data->end; } return(myStack);
main.c
#include <stdio.h> #include "stack.h" int main() { Node *tmp; Stack *myStack(0); myStack=mkstack(0); tmp=create(); tmp->value=fgetc(stdin); fgetc(stdin); while(tmp->value !='\n') { myStack=push(myStack, tmp); tmp=create(); tmp->value=fgetc(stdin); fgetc(stdin); } printf("Linked list has %d nodes\n", myStack->data->qty); printf("String is: "); do { tmp=pop(&myStack); if(tmp !=NULL) { printf("%c", tmp->value); } } while (tmp !=NULL); printf("\n"); return(0); }
Work day, work day, every one loves a work day, a work day, a workday…..
clear node command….
Node *clear(Node *list) { Node *tmp = list; Node *tmp2; int count; while(tmp!=NULL) { tmp=tmp->next; count++; } tmp=list; for(; count>0 ; count--) { tmp2=tmp->next; tmp->next=NULL; free(tmp); tmp=tmp2; } return(NULL); }
TURTLE DAY!!!!
_ .-./*) _/___/ `. U U 'You can look up the manual page for a command by typing 'man command'.'
on a Lab46 terminal: cd /var/public/data/fall2013/Linkedlistimp
To copy into your ~/src/data/directory: make copy … or copy it manually to your destination of choice
Make help….
lab46:~/src/data$ make help ****************[ Data Structures List Implementation ]***************** ** make - build everything ** ** make debug - build everything with debug symbols ** ** ** ** make testing - build unit tests ** ** make testing-debug - build unit tests with debugging symbols ** ** make libs - build all supporting libraries ** ** make libs-debug - build all libraries with debug symbols ** ** ** ** make clean - clean; remove all objects/compiled code ** ** make help - this information ** ************************************************************************
lab46:~/src/data$ make debug make[1]: Entering directory `/home/cgaines/src/data/src' make[2]: Entering directory `/home/cgaines/src/data/src/list' ar rcs ../../lib/liblist.a make[2]: Leaving directory `/home/cgaines/src/data/src/list' make[2]: Entering directory `/home/cgaines/src/data/src/node' gcc -Wall -I ../../inc -DDEBUG -g -c cp.c gcc -Wall -I ../../inc -DDEBUG -g -c mk.c gcc -Wall -I ../../inc -DDEBUG -g -c rm.c ar rcs ../../lib/libnode.a cp.o mk.o rm.o make[2]: Leaving directory `/home/cgaines/src/data/src/node' make[2]: Entering directory `/home/cgaines/src/data/src/stack' gcc -Wall -I ../../inc -DDEBUG -g -c peek.c peek.c: In function 'peek': peek.c:6: warning: control reaches end of non-void function gcc -Wall -I ../../inc -DDEBUG -g -c pop.c gcc -Wall -I ../../inc -DDEBUG -g -c push.c gcc -Wall -I ../../inc -DDEBUG -g -c stackops.c ar rcs ../../lib/libstack.a peek.o pop.o push.o stackops.o make[2]: Leaving directory `/home/cgaines/src/data/src/stack' make[1]: Leaving directory `/home/cgaines/src/data/src'
Queue - a very British line… - sometimes known as buffer
enqueue - you enter the back of the line
dequeue - you emerge from the front of the line
Stack
FIFO - first in first out
LILO - last in last out
Queue *mkqueue(bufsize) Queue *enqueue(Queue *, Node *) <- Node *dequeue(Queue **);
struct queue { List *data; Node *front; Node *back; int bufsize; }; typedef struct queue Queue;
lab46:/var/public/data/fall2013$
lab46:/var/public/data/fall2013/Linkedlistimp
Binary Tree (is not really a family tree because a family tree can have more then two)
vvvvvv
vvvvv
vvvv
vvv
vv
v
o - root
one parent - two children, then children having children… so on and so forth. (family tree of nodes)
BUILD A BINARY TREE PROGRAM!!!!
_ .-./*) _/___/ `. U U 'You can compile a C program with 'gcc'.'
WORKDAY!!!!
TURTLE DAY!!!!
_ .-./*) _/___/ `. U U 'You can view the standard MOTD by typing 'motd'.'
“LET'S GET READY TO RUMBLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!!!”
Preview to EoCE
lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ ls Makefile inc lib src testing lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ cd inc lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/inc$ ls list.h node.h queue.h stack.h lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/inc$ cd /var/public/data/fall2013/EoCE/ll_oop_reimp/ lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ cd lib lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/lib$ ls lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/lib$ cd /var/public/data/fall2013/EoCE/ll_oop_reimp/ lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ ls Makefile inc lib src testing lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ cd src lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/src$ ls Makefile btree list node queue stack lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/src$ cd /var/public/data/fall2013/EoCE/ll_oop_reimp/ lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp$ cd testing lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/testing$ ls Makefile stacktest.cc lab46:/var/public/data/fall2013/EoCE/ll_oop_reimp/testing$
stacktest.cc
#include <stdio.h> #include "stack.h" int main() { Node *tmp = new Node; Stack *myStack = new Stack(0); tmp -> setValue(fgetc(stdin)); fgetc(stdin); while(tmp->getValue() != '\n') { myStack -> push(tmp); tmp = new Node(fgetc(stdin)); fgetc(stdin); } fprintf(stdout, "linked list has %d nodes\n", myStack -> getListSize()); fprintf(stdout, "String is: "); tmp = myStack -> pop(); while (tmp != NULL) { fprintf(stdout, "%c", tmp -> getValue()); delete tmp; tmp = myStack -> pop(); } while(tmp != NULL); fprintf(stdout, "\n"); return(0); }
_ .-./*) _/___/ `. U U 'You can check your group affiliations by typing 'group'.'
Some of my book collection that will be saving me from destruction. But not self destruction.
GNU nano 2.2.4 File: linkedlist_2.c
#include<stdio.h> #include<stdlib.h> struct node{ int value; struct node *next; }; typedef struct node Node; int main() { int input = 0; int seeker; Node *list, *tmp, *tmp2; list = tmp = tmp2 = NULL; while( input != -1 ) { printf("Enter a value (-1 to end): "); scanf("%d", &input); if( input != -1) { if( list == NULL ) { list = tmp = (Node*)malloc(sizeof(Node)); tmp->next = NULL; list->value = input; } else { tmp->next = (Node*)malloc(sizeof(Node)); tmp->next->next = NULL; tmp->next->value = input; tmp = tmp->next; } } } tmp = list; input = 0; while( tmp != NULL ) { printf("[%d] %d\n", input, tmp->value); tmp = tmp->next; input++; } printf("NULL\n"); //Insert into list printf("Which node would you like to insert before: "); scanf("%d", &input); tmp = list; for( seeker = 0; seeker < (input-1); seeker++ ) tmp = tmp->next; if( input==0) { printf("Enter value for new node:"); scanf("%d", &input); tmp2 = (Node*)malloc(sizeof(Node)); tmp2->value = input; tmp2->next = NULL; tmp2->next = tmp; list = tmp2; } else { printf("Enter a value to insert: "); scanf("%d", &input); tmp2 = (Node*)malloc(sizeof(Node)); tmp2->value = input; tmp2->next = tmp->next; tmp->next = tmp2; } tmp = list; input = 0; while( tmp != NULL ) { printf("[%d] %d\n", input, tmp->value); tmp = tmp->next; input++; } return(0); }
RASPBERRY PI!!!!!
Trying to learn more about this Pi.
Raspberry Pi YouTube videos and tutorials by Tim Rogers.
Learning Raspberry Pi history…
http://www.raspberrypi.org/about
Thinking about children and their use of technology.
Got project 1 completed with two fellow class mates
Create a GPIO file access: echo 11 > /sys/class/gpio/export Configure the Pin Direction (In/Out): echo out > /sys/class/gpio/gpio11/direction Write a value to turn on the LED using the GPIO11: echo 1 > /sys/class/gpio/gpio11/value Now your led should be ON!!! Write a value to clear the LED using the GPIO11 echo 0 > /sys/class/gpio/gpio11/value Now your led should be OFF!!! Delete the created GPIO (11) echo 11 > /sys/class/gpio/unexport You are able to access to GPIO using python or any programming language. We wrote a python script to show how. Download Open a new terminal and execute the script wget https://sites.google.com/site/semilleroadt/raspberry-pi-tutorials/gpio/ADT_blink.py python ADT_blink
Redone in C….
#include "rpi.h" int main() { if(map_peripheral(&gpio) == -1) { printf("Failed to map the physical GPIO registers into the virtual memory space.\n"); return -1; } // Define pin 7 as output INP_GPIO(7); OUT_GPIO(7); while(1) { // Toggle pin 7 (blink a led!) GPIO_SET = 1 << 7; sleep(1); GPIO_CLR = 1 << 7; sleep(1); } return 0; }
Project ideas….. Organize shelves and move them. fix docking stations.
Organize shelves, look for containers, verify prices with affordability.
Working on patterns for Velcro-ing the Docking Station to lab tables. Looking at plastic containers for storage of cables and computer parts.
Bought some plastic containers for storage. Working on organization and bundling cords. Walmart still does not have the Velcro I need to properly mount the docking stations to the desks. Will continue to organize and obtain more plastic containers.
Placed Velcro on the bottom of most of the plugable docking stations on the tables. STATION TWO is tied down at the moment. One broken plugable on STATION TWO that needs to be fixed. STATION THREE has been all done.