ENEE150 Discussion 04 Section 0101 Adam Wang.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Introduction to Assembly language
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Kernighan/Ritchie: Kelley/Pohl:
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Pointers and Arrays C and Data Structures Baojian Hua
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Using Unix Shell Scripts to Manage Large Data
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Programming With C.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
ENEE150 – 0102 ANDREW GOFFIN Testing and Debugging.
C Programming in Linux Jacob Chan. C/C++ and Java  Portable  Code written in one system and works in another  But in C, there are some libraries that.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
1 Workin’ with Pointas An exercise in destroying your computer.
C++ Pointers Review. Overview  What is a pointer  Why do I care?  What can be 'pointed to'?  Example.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
ENEE150 – 0102 ANDREW GOFFIN More With Pointers. Importance of Pointers Dynamic Memory (relevant with malloc) Passing By Reference Pointer Arithmetic.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Lecture 3 Translation.
Computer Organization and Design Pointers, Arrays and Strings in C
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Whatcha doin'? Aims: To start using Python. To understand loops.
User-Written Functions
Department of Computer Engineering
Using Unix Shell Scripts to Manage Large Data
Introduction to Programming Using C
A bit of C programming Lecture 3 Uli Raich.
ENEE150 Discussion 07 Section 0101 Adam Wang.
Computer Programming Techniques Semester 1, 1998
CSE 390a Lecture 5 Intro to shell scripting
ENEE150 Discussion 02 Section 0101 Adam Wang.
ENEE150 Discussion 09 Section 0101 Adam Wang.
Functions, locals, parameters, and separate compilation
ENEE150 Discussion 06 Section 0101 Adam Wang.
Lecture 11 bash scripting overview c programming overview moving data between c and bash memory and pointers.
ENEE150 Discussion 13 Section 0101 Adam Wang.
C Basics.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Functions Inputs Output
Introduction to the C Language
Object Oriented Programming COP3330 / CGS5409
Common C Programming Errors, GDB Debugging
CSC 253 Lecture 6.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Programming Fundamentals Lecture #3 Overview of Computer Programming
Your questions from last session
Simulating Reference Parameters in C
CSCE 206 Lab Structured Programming in C
Intro to shell scripting
In C Programming Language
Functions continued.
A First Program.
C Programming Pointers
Introduction to Python
CSCE 206 Lab Structured Programming in C
EN Software Carpentry Python – A Crash Course Esoteric Sections Compiled Languages.
Functions, Part 2 of 42 Topics Functions That Return a Value
Introduction to Pointers
Presentation transcript:

ENEE150 Discussion 04 Section 0101 Adam Wang

Overview HW2 Pointers

HW 2 Problem 1 Write your own “tests” to test the check functions in project 1 Check_basic_move Check_entry_move Check_bear_off_move Check_die Check_board_bounds You’ll submit 5 programs: test1-driver.c -> test5-driver.c Just print out whatever’s in the out files

What you’re given required_functions.o Test1.out -> test5.out Contains the 5 check functions and print_board() A *.o file is compiled but not linked; you can use it but you won’t be able to see the code Use like you would use a *.c file Test1.out -> test5.out All the output you need to be able to print with the driver programs Copy in your backgammon.h for the function headers and global variables

Test1.out Put 1 white piece on the_board_white[6] You’ll first need to clear the board Go through the_board[] and set everything to 0 Put 1 white piece on the_board_white[6] Print_board Use simple if statements to decide if you should print “VALID_MOVE” or “INVALID_MOVE” Next put 1 red piece on the_board_red[1] Print board again Do same thing over again

Problem 2: run-tests Write a script file to automatically compile & diff all your files This is NOT a *.c file; this is a shell language Should be ~10 lines of commands

Tips to write the script First line must be #!/bin/csh This tells the shell it’s a cshell script The command to print is echo echo “hello world” A “for” loop looks like this: foreach i (1 2 3 4 5 6) ... other commands go here (gcc, diff, a.out, etc.) end

Other tips In a for loop you can use the value of i in your commands test$i-driver.c Replaces “$i” with whatever value i is After you’ve written and saved, you need to change permissions Type “chmod 777 run-tests” to give yourself executable permissions Then you can run the script just by typing run-tests

Pointers Stores a memory address in hex Can also say it’s a “reference” to another variable or value To initialize a pointer: int *p; Right now this memory address points to garbage & - get the memory address of a variable &a * - get the value at the pointer *p Also “dereference” a pointer

Examples int *p; // new pointer p int *q; int a, b, x; a = 5; *p = a; // set the value of p to whatever’s a b = 6; q = &b; // set q to the memory address of b b = 7; // what happens? q = p; // valid x = *p + 5;

Where have we seen pointers already FILE * inFile; inFile = fopen(“data.txt”, “r”); Stores a pointer to a FILE data type Scanf(“%d”, &var); Reads in an integer and stores it into var Why do we need to do this?

swap void swap (int a, int b) { int temp = a; a = b; b = temp; } int a = 5, b = 10; swap (a,b); // Does NOT work; pass by VALUE

Let’s consider this new swap function void swap (int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int p, q; p = 5; q = 10; swap (&p, &q); //This works because of pass by REFERENCE