Homework Reading Programming Assignments

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Chapter 11 Introduction to Programming in C
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Homework Starting Chapter 2 K&R. Read ahead. Questions?
Advanced Topics Object-Oriented Programming Using C++ Second Edition 13.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Introduction to a Programming Environment
Guide To UNIX Using Linux Third Edition
Data Representation in Computers
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Data Storage Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas Faculty of Information Technology Islamic.
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
C Tutorial Session #2 Type conversions More on looping Common errors Control statements Pointers and Arrays C Pre-processor Makefile Debugging.
Robert Crawford, MBA West Middle School.  Explain how the binary system is used by computers.  Describe how software is written and translated  Summarize.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
1 Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 at end of class today –Continue working on HW3 Questions?
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Topic 14.1 Extended Hexadecimal  Decimal is base 10 and uses 10 digits (0,1,2,3,4,5,6,7,8,9).  Binary is base 2 and uses 2 digits (0,1).  Computers.
Characters and Strings
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
Comp 335 – File Structures Hexadecimal Dumps Interpreting File Contents.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
NXT File System Just like we’re able to store multiple programs and sound files to the NXT, we can store text files that contain information we specify.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Binary a. express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal;
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
DEBUG.
Binary Representation in Text
Binary Representation in Text
EET 2259 Unit 13 Strings and File I/O
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
The Machine Model Memory
Unit 18: Computational Thinking
© 2016 Pearson Education, Ltd. All rights reserved.
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
Assembly Language Programming Part 3
Debugging with gdb gdb is the GNU debugger on our CS machines.
Guide To UNIX Using Linux Third Edition
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Data Storage Introduction to computer, 2nd semester, 2010/2011
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Common C Programming Errors, GDB Debugging
File Input and Output.
Your questions from last session
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Homework Reading Programming Assignments Finish K&R Chapter 1
EET 2259 Unit 13 Strings and File I/O
Presentation transcript:

Homework Reading Programming Assignments Finish K&R Chapter 1 (if not done yet) Start K&R Chapter 2 for next time. Programming Assignments Finish HW1 assignment (if not done yet) Continue HW2 assignment

“Octal” Dump Use “od –x” to see hex dump of a file od –x trim.in . . . 00000120 7061 7274 .… 0a0a Octal and Hexadecimal numbers Why dump in Hex instead of Octal? ASCII code for representing characters

Octal and Hex Numbers People normally deal in numbers base 10 Computers normally deal in numbers base 2 The problem: Reading a long string of 1’s and 0’s not easy Conversion between base 2 and base 10 not easy The solution: Convert binary digit strings to Octal or Hex Easily done because 23 = 8 and 24 = 16

Octal and Hex Numbers Look at a long string of binary digits in groups Group from right by 3 digits for Octal Group from right by 4 digits for Hex See the following examples: Binary Digits Grouped by threes For Octal Grouped by fours For Hex Don’t convert binary to/from Hex/Octal via decimal! 011010101100 011 010 101 100 0 3 2 5 4 0110 1010 1100 0x 6 a c

Octal and Hex Numbers Octal (Octal Constant is written 0dd…) OCTAL BINARY OCTAL BINARY 0 000 4 100 1 001 5 101 2 010 6 110 3 011 7 111 Note: Can’t write a decimal value with a leading 0 digit – will be interpreted as octal

Octal and Hex Numbers Hex (Hex Constant is written 0xdd…) HEX BIN. HEX BIN. HEX BIN. HEX BIN. 0 0000 4 0100 8 1000 C 1100 1 0001 5 0101 9 1001 D 1101 2 0010 6 0110 A 1010 E 1110 3 0011 7 0111 B 1011 F 1111 NOTE: Memorize these translations DO NOT convert between binary and Hex or Octal by converting to decimal and back! Much harder!!

ASCII Code For computers to process our letters, digits, punctuation marks, etc, we need a binary code for each such “character”. American Standard Code for Information Interchange (ASCII) provides these codes. See ASCII code chart (from Lecture 2) Standard 8 bit bytes and 16 bit words are not integer multiples of 3 bits but are integer multiples of 4 bits – favoring use of Hex!

ASCII Codes in visitype.c To convert a character’s (integer) value to a printable ASCII string for what it represents: We need a table of 4 byte character strings each ending in a zero byte (created by using “\0”) Arranged in the order of the character values used in the ASCII code to represent them And to create the address of one of these strings to pass to function printf e.g. &asciiname[4*i]

Analysis of visitype.c See separate program text “visitype.c” ASCII code conversion array char asciiname [] = …. ; Initialization values for the array 128 strings of length 4 including the ‘\0’ … asciiname[0] …[1] …[2] …[3] …[4] …[5] …[6] …[7] ‘N’ ‘U’ ‘L’ ‘\0’ ‘S’ ‘O’ ‘H’ ‘\0’ …

Analysis of visitype.c There are a few characters which can't be placed in the quoted initialization string directly, for example " and \. "∆∆"\0" (where " is hex 22) Problem is that " as a character will be interpreted as the end of string. We need to indicate that it is quoted, that it is to be taken literally by the compiler as an ASCII value, and the way to do that is precede it by a \.  "∆∆\"\0" (where " is hex 22) Now there seem to be five chars in that string, “∆∆\"\0” But there are not, \" is a single character value, just as \0 is

Analysis of visitype.c What other characters MAY need the same special treatment? See K&R page 193. Good page to mark for open book tests! Do all of these require special treatment here? No, which one other than \“ needs it? Answer: (write in here) _________

Analysis of visitype.c Access the strings in the array (i = 0 to 127) asciiname[4*i] Array index 4*i indicates start of each string However, printf needs a pointer to a string &asciiname[4*i] The “&” is the “address of” operator Take on faith for now - more on pointers later

More on Debugging How to debug. See Users Guide to Tools http://www.cs.umb.edu/helproot/cs240/cs240.html A professional programmer uses a Debugger, rather than putting in lots of printf statements to track down a bug. (Note: In some cases such as real time programs, you can’t stop the program with a debugger, you may need to use “printf” or “log” statements.)

Use of Debugger - gdb Start with the correct compiler options: gcc -g vt.c -o vt -g for debug -o replaces a.out with filename vt Now, instead of just typing program name: gdb vt Gives message: Ready to run -- not yet running.

Use of Debugger - gdb Want to interact with running program, not just let it run free to end. Type: b main break at main() To run the program via the debugger r <vt.in run, taking stdin from vt.in Will stop when encounters main() in program execution -- often lot of things done first. Now can single step through program, s or n (skip entering functions), put out values of variables.

Use of Debugger - gdb Examples of gdb commands: p i (print value of variable i) p 3*i (print value of expression 3*i) p/x i (print in hex format value of variable i) i lo ("info" - give values of all local variables) h (help -- pretty good messages -- lists topics) h topic (help on named topic) h p (help on command p for printf) q TO QUIT (leave debugger)

Use of Debugger - gdb More complex gdb commands in UNIX Guide. Setting breaks/conditional breaks at line numbers: b 36 b fn.c:22 if i == 3 Getting line numbers from "list" or "l" command: l 22 print 10 lines around line 22 in main l fn.c list first five lines, then l means next 10 lines i b to get info on breakpoints d 3 to delete bkpt 3 c for continue after bkpt encountered

Debugging “core” files If you compile a program with –g option, run it, and it crashes, e.g. “segmentation fault – core dumped”, you can use gdb to the analyze the state of the program at the point where it crashed. Use the gdb command with two parameters: gdb <program file name> <core file name> Example: gdb buggy core Use all gdb commands as usual – except step, next, or continue since the program has already crashed. Display variable values, etc. to debug.