ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Size: px
Start display at page:

Download "ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters"

Transcription

1 The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers char variables mostly used to store characters encoded in ASCII. Only store characters in char variables in COMP1911. Even if a numeric variable is only use for the values 0..9, use the type int for the variable. ASCII ( American Standard Code for Information Interchange) specifies encoding for 128 characters to the integers The characters encoded include upper and lower case (English) letters, digits, common punctuation symbols (as you might find on the keyboard) plus a series of non-printable control characters (including newline and tab). Manipulating Characters Manipulating Characters Does this mean you will have to remember 100+ character codes!? Luckily no! We use character literals instead! For example: char a = a ; // ASCII code 97 char A = A ; // ASCII code 65 char space = ; // ASCII code 32 char p l u s = + ; // ASCII code 43 char n e w l i n e = \ n ; // ASCII code 10 Style Note Always use character literals in your code! Even if you are really proud of having memorised the ASCII Table! NOTE The ASCII codes for the digits (48 57), the upper case letters (65 90) and lower case letters (97 122) are in sequence. Knowing this allows us to do some neat things: i n t a = a ; i n t b = a + 1 ; // t h i s i s p o s s i b l e due to i n t c = a + 2 ; // the u n d e r l y i n g numeric type i n t B = b ( a A ) ;

2 Manipulating Characters Printing and Reading Characters We can also test various properties of characters: // check f o r l o w e r c a s e i f ( c >= a && c <= z ) { Problem: Convert a digit character to the integer it represents, e.g., 0 0, 7 7, etc. We use the fact that the digits codes are in order: // check i s a d i g i t i f ( c >= 0 && c <= 9 ) { v a l = c 0 ; // why does t h i s work? C provides library functions for reading and writing characters The getchar function This function reads and returns one input character. Note that, unlike scanf, it has no arguments; its return value is collected by assigning it to a variable. The putchar function This function takes a single int argument and prints it out Here is an example: i n t c ; p r i n t f ( P l e a s e e n t e r a c h a r a c t e r : ) ; c = g e t c h a r ( ) ; p u t c h a r ( c ) ; Reading Characters Reading Characters Consider the following code: i n t c1, c 2 ; p r i n t f ( P l e a s e e n t e r f i r s t c h a r a c t e r : \ n ) ; c1 = g e t c h a r ( ) ; p r i n t f ( P l e a s e e n t e r second c h a r a c t e r : \ n ) ; c2 = g e t c h a r ( ) ; p r i n t f ( F i r s t %c \ nsecond : %c \n, c1, c2 ) ; What is the output? Turns out that the newline input by pressing Enter after the first character is read by the second getchar. How can we fix the program? i n t c1, c2 ; p r i n t f ( P l e a s e e n t e r f i r s t c h a r a c t e r : \ n ) ; c1 = g e t c h a r ( ) ; g e t c h a r ( ) ; // r e a d s and d i s c a r d s a c h a r a c t e r p r i n t f ( P l e a s e e n t e r second c h a r a c t e r : \ n ) ; c2 = g e t c h a r ( ) ; p r i n t f ( F i r s t : %c \ nsecond : %c \n, c1, c2 ) ; Printing characters The conversion specifier for characters is %c. Using it we can supply variables of char type to printf for output:

3 End of Input An input funcion can such as scanf or getchar can fail because there is no input is available. This can occur, for example, if input is coming from a file and the end of the file is reached. On UNIX-like systems such Linux & OSX typing Ctrl + D on a terminal signals to the operating system there is no more input from the terminal. Windows has no equivalent, but some windows program interprert Ctrl + Z similarly. getchar returns a special non-ascii value to indicate there is no input was available. This non-ascii value is #defined as EOF in stdio.h. On most systems EOF == -1. Note -1, isn t an ASCII value (0..127) There is no end-of-file character on Linux or other modern operating systems. Reading Characters to End of Input Programming pattern for reading characters to the end of input: i n t ch ; ch = g e t c h a r ( ) ; w h i l e ( ch!= EOF) { p r i n t f ( you e n t e r e d the c h a r a c t e r : %c which ha ch = g e t c h a r ( ) ; For comparison the programming pattern for reading integers to end of input: i n t num ; // s c a n f r e t u r n s the number o f i t e m s read w h i l e ( s c a n f ( %d, &num) == 1) { p r i n t f ( you e n t e r e d the number : %d\n, num ) ; Strings A string is a sequence of characters. C uses a special ASCII character \0 to mark the end of strings. This is convenient because programs don t have to track the lnegth of the string. Definition A C string is a null-terminated character array. Consider the following: // t h i s i s i n c o r r e c t, \ 0 w i l l be d i s c a r d e d c h a r h e l l o [ 5 ] = { h, e, l, l, o, \ 0 ; // t h i s i s OK c h a r h e l l o [ 6 ] = { h, e, l, l, o, \ 0 ; // t h i s i s b e t t e r c h a r h e l l o [ ] = { h, e, l, l, o, \ 0 ; Useful C Library Functions for Characters The C library includes some useful functions which operate on characters. Several of the more useful listed below. Note the you need to #include <ctype.h> to use them. #i n c l u d e <c t y p e. h> i n t t o u p p e r ( i n t c ) ; // c o n v e r t c to upper c a s e i n t t o l o w e r ( i n t c ) ; // c o n v e r t c to l o w e r c a s e i n t i s a l p h a ( i n t c ) ; // t e s t i f c i s a l e t t e r i n t i s d i g i t ( i n t c ) ; // t e s t i f c i s a d i g i t i n t i s l o w e r ( i n t c ) ; // t e s t i f c i s a l o w e r c a s e l e t t e r i n t i s u p p e r ( i n t c ) ; // t e s t i f c i s a upper c a s e l e t t e r String Length The null character must be accounted for when sizing strings, although, somewhat confusingly, the library function strlen returns the length of a string not including the null character.

4 Strings Reading an Entire Input Line Because working with strings is so common, C provides some convenient syntax. Instead of writing: char h e l l o [ ] = { h, e, l, l, o, \ 0 ; You can write char h e l l o [ ] = h e l l o ; Note hello will have 6 elements The compiler automatically appends \0 when strings are initialised with string literals. Again, remember to allow space for it if sizing the array manually. The function fgets reads an entire line: #d e f i n e MAX LINE LENGTH 1024 char l i n e [ MAX LINE LENGTH ] ; f g e t s ( l i n e, MAX LINE LENGTH, s t d i n ) ; f p u t s ( l i n e, s t d o u t ) ; Reading an Entire Input Line Reading Lines to End of Input You might use fgets as follows: #d e f i n e MAX LINE LENGTH 1024 char l i n e [ MAX LINE LENGTH ] ; f g e t s ( l i n e, MAX LINE LENGTH, s t d i n ) ; f p u t s ( l i n e, s t d o u t ) ; // e q u i v a l e n t to p r i n t f ( % s, l i n e ) Programming pattern for reading lines to end of input: // f g e t s r e t u r n s NULL i f i t can t r e a d any c h a r a c t e r s w h i l e ( f g e t s ( l i n e, MAX LINE, s t d i n )!= NULL) { p r i n t f ( you e n t e r e d t h e l i n e : %s, l i n e ) ;

5 String Manipulation String Manipulation The header file string.h provides some useful string functions: // s t r i n g l e n g t h ( not i n c l u d i n g \ 0 ) s i z e t s t r l e n ( c o n s t c h a r s ) ; // s t r i n g copy c h a r s t r c p y ( c h a r dest, c o n s t c h a r s r c ) ; c h a r s t r n c p y ( c h a r dest, c o n s t c h a r s r c, s i z e t n ) ; // s t r i n g c o n c a t e n a t i o n / append c h a r s t r c a t ( c h a r dest, c o n s t c h a r s r c ) ; c h a r s t r n c a t ( c h a r dest, c o n s t c h a r s r c, s i z e t n ) ; // s t r i n g compare i n t strcmp ( c o n s t c h a r s1, c o n s t c h a r s2 ) ; i n t strncmp ( c o n s t c h a r s1, c o n s t c h a r s2, s i z e t n ) ; i n t s t r c a s e c m p ( c o n s t c h a r s1, c o n s t c h a r s2 ) ; i n t s t r n c a s e c m p ( c o n s t c h a r s1, c o n s t c h a r s2, s i z e t n ) ; // c h a r a c t e r s e a r c h c h a r s t r c h r ( c o n s t c h a r s, i n t c ) ; c h a r s t r r c h r ( c o n s t c h a r s, i n t c ) ; #i n c l u d e < s t r i n g. h> c h a r s t r 1 [ ] = H e l l o World! ; c h a r s t r 2 [ ] ; s t r n c p y ( s t r 2, s t r 1, ) ; // copy s t r 1 to s t r 2 i f ( strcmp ( s t r 1, s t r 2 ) == 0) { // case s e n s i t i v e compare p r i n t f ( S t r i n g s match! \ n ) ; // append s t r 1 to s t r 2 s t r n c a t ( s t r 2, s t r 1, 100 ( s t r l e n ( s t r 2 ) + 1 ) ) ; i f ( s t r c a s e c m p ( s t r 1, s t r 2 ) ) { // case i n s e n s i t i v e compare p r i n t f ( S t r i n g s do not match! \ n ) ; p r i n t f ( %d\n, s t r l e n ( s t r 2 ) ) ; // s t r i n g l e n g t h Note that strlen does not count the null character! String Manipulation Strings Remember You can find out about what else is available in string.h by running man string. When working with strings we use the null character as a guard: c h a r s t r 1 [ ] = H e l l o World! ; c h a r s t r 2 [ ] ; i n t i ; // the f o l l o w i n g code c o p i e s s t r 1 i n t o s t r 2 i = 0 ; // s t a r t at i n d e x 0 w h i l e ( s t r 1 [ i ]!= \ 0 ) { // s t o p on n u l l s t r 2 [ i ] = s t r 1 [ i ] ; // copy i n d i v i d u a l c h a r a c t e r s i = i + 1 ; // i n c r e m e n t i n d e x s t r 2 [ i ] = \ 0 ; // MUST s e t t h i s f o r s t r 2! In summary strings: are null-terminated character arrays can be initialised with string literals can be manipulated by scanf/printf, use %s benefit from the string manipulation functions in string.h since they are arrays they cannot be copied via assignment (=) Careful The main error encountered when working with strings is mishandling the terminating null character, e.g., forgetting to set it! Check this first if your strings are behaving strangely.

6 Arrays of Strings Command-line Arguments Sometimes, instead of manipulating each individual cell, as for matrices, we need to manipulate whole arrays. This is generally the case when working with arrays of strings! Consider: c h a r names [ 3 ] [ 2 0 ] = { Mark, Luke, John ; // why does t h i s work? p r i n t f ( % s %s %s \n, names [ 0 ], names [ 1 ], names [ 2 ] ) ; Array of arrays If we take this view (array of arrays!) of 2D arrays, it makes sense why using only the first index gives us a whole array! What are command-line arguments? Arguments that are supplied to a program when it is run. We have seen them already, for example: % diff -i file1.txt file2.txt % gedit prog.c Here, -i, file1.txt and file2.txt are command-line arguments to diff and prog.c is a command-line argument to gedit. Command-line arguments are automatically supplied to our C programs, by the operating system, via the arguments of the main function (argc and argv)! i n t main ( i n t argc, char argv [ ] ) { Command-line Arguments Command-line Arguments Arguments to main argc stores the number of command-line arguments argv stores the command-line arguments as strings i n t main ( i n t argc, c h a r a r g v [ ] ) { i n t i ; f o r ( i = 0 ; i < a r g c ; i = i + 1) { // p r i n t arguments p r i n t f ( Argument %d i s : %s \n, i + 1, a r g v [ i ] ) ; NB The first argument is always the program name! This means that argc is always at least 1 and argv contains at least one value. By default, command-line arguments are space delimited. We can use quotes if arguments include spaces. %./prog1 nospace one space %./prog2 nospace "one space" In the above, prog1 sees three command-line arguments, while prog2 sees only two. What about? %./prog3 *.c %./prog4 10 < in > out Sometimes argv is typed as: char **argv.

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

5 Arrays and Pointers

5 Arrays and Pointers 5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

More information

File Handling. What is a file?

File Handling. What is a file? File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Encoding of alphanumeric and special characters As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Alphanumeric

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Chapter 13 - The Preprocessor

Chapter 13 - The Preprocessor Chapter 13 - The Preprocessor Outline 13.1 Introduction 13.2 The#include Preprocessor Directive 13.3 The#define Preprocessor Directive: Symbolic Constants 13.4 The#define Preprocessor Directive: Macros

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

C Examples! Jennifer Rexford!

C Examples! Jennifer Rexford! C Examples! Jennifer Rexford! 1 Goals of this Lecture! Help you learn about:! The fundamentals of C! Deterministic finite state automata (DFA)! Expectations for programming assignments! Why?! The fundamentals

More information

60-141 Introduction to Programming II Winter, 2014 Assignment 2

60-141 Introduction to Programming II Winter, 2014 Assignment 2 60-141 Introduction to Programming II Winter, 2014 Assignment 2 Array In this assignment you will implement an encryption and a corresponding decryption algorithm which involves only random shuffling of

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

Module 816. File Management in C. M. Campbell 1993 Deakin University

Module 816. File Management in C. M. Campbell 1993 Deakin University M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

More information

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com) Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable

More information

Introduction to Perl

Introduction to Perl Introduction to Perl March 8, 2011 by Benjamin J. Lynch http://msi.umn.edu/~blynch/tutorial/perl.pdf Outline What Perl Is When Perl Should Be used Basic Syntax Examples and Hands-on Practice More built-in

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

C Strings and Pointers

C Strings and Pointers Motivation The C++ string class makes it easy to create and manipulate string data, and is a good thing to learn when rst starting to program in C++ because it allows you to work with string data without

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

CS106A, Stanford Handout #38. Strings and Chars

CS106A, Stanford Handout #38. Strings and Chars CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

How To Write Portable Programs In C

How To Write Portable Programs In C Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar Lexical Analysis and Scanning Honors Compilers Feb 5 th 2001 Robert Dewar The Input Read string input Might be sequence of characters (Unix) Might be sequence of lines (VMS) Character set ASCII ISO Latin-1

More information

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG Channel Access Client Programming Andrew Johnson Computer Scientist, AES-SSG Channel Access The main programming interface for writing Channel Access clients is the library that comes with EPICS base Written

More information

Project 2: Bejeweled

Project 2: Bejeweled Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

SPSS for Windows importing and exporting data

SPSS for Windows importing and exporting data Guide 86 Version 3.0 SPSS for Windows importing and exporting data This document outlines the procedures to follow if you want to transfer data from a Windows application like Word 2002 (Office XP), Excel

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Simple Image File Formats

Simple Image File Formats Chapter 2 Simple Image File Formats 2.1 Introduction The purpose of this lecture is to acquaint you with the simplest ideas in image file format design, and to get you ready for this week s assignment

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Converting Microsoft Access 2002 to Pipe-Delimited ASCII Text Files

Converting Microsoft Access 2002 to Pipe-Delimited ASCII Text Files Converting Microsoft Access 2002 to Pipe-Delimited ASCII Text Files Using the Windows XP 2002 Professional Operating System with Service Pack 2 (SP2) Note: Participants must return local Address Lists

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

FTP client Selection and Programming

FTP client Selection and Programming COMP 431 INTERNET SERVICES & PROTOCOLS Spring 2016 Programming Homework 3, February 4 Due: Tuesday, February 16, 8:30 AM File Transfer Protocol (FTP), Client and Server Step 3 In this assignment you will

More information

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include

More information

Number Representation

Number Representation Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

Operating Systems and Programming Languages

Operating Systems and Programming Languages Introduction First Year Computing Course: An introduction to procedural programming Dr G. A. Wynn, Dr R. G. West, Prof. R. Willingale Department of Physics & Astronomy, University of Leicester September

More information

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.

More information

Crash Dive into Python

Crash Dive into Python ECPE 170 University of the Pacific Crash Dive into Python 2 Lab Schedule Ac:vi:es Assignments Due Today Lab 11 Network Programming Due by Dec 1 st 5:00am Python Lab 12 Next Week Due by Dec 8 th 5:00am

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

CS 103 Lab Linux and Virtual Machines

CS 103 Lab Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation

More information

Time Clock Import Setup & Use

Time Clock Import Setup & Use Time Clock Import Setup & Use Document # Product Module Category CenterPoint Payroll Processes (How To) This document outlines how to setup and use of the Time Clock Import within CenterPoint Payroll.

More information

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration This JavaScript lab (the last of the series) focuses on indexing, arrays, and iteration, but it also provides another context for practicing with

More information

SAPScript. A Standard Text is a like our normal documents. In Standard Text, you can create standard documents like letters, articles etc

SAPScript. A Standard Text is a like our normal documents. In Standard Text, you can create standard documents like letters, articles etc SAPScript There are three components in SAPScript 1. Standard Text 2. Layout Set 3. ABAP/4 program SAPScript is the Word processing tool of SAP It has high level of integration with all SAP modules STANDARD

More information

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window) 1 ASCII TABLE 2 ASCII TABLE (DOS) 3 ASCII TABLE (Window) 4 Keyboard Codes The Diagram below shows the codes that are returned when a key is pressed. For example, pressing a would return 0x61. If it is

More information

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr; 50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes Computer Systems II Creating and Executing Processes 1 Unix system calls fork( ) wait( ) exit( ) 2 How To Create New Processes? Underlying mechanism - A process runs fork to create a child process - Parent

More information

Programming Project 1: Lexical Analyzer (Scanner)

Programming Project 1: Lexical Analyzer (Scanner) CS 331 Compilers Fall 2015 Programming Project 1: Lexical Analyzer (Scanner) Prof. Szajda Due Tuesday, September 15, 11:59:59 pm 1 Overview of the Programming Project Programming projects I IV will direct

More information

Encoding Text with a Small Alphabet

Encoding Text with a Small Alphabet Chapter 2 Encoding Text with a Small Alphabet Given the nature of the Internet, we can break the process of understanding how information is transmitted into two components. First, we have to figure out

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

Introduction to Python

Introduction to Python Introduction to Python Sophia Bethany Coban Problem Solving By Computer March 26, 2014 Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Visual Basic Programming. An Introduction

Visual Basic Programming. An Introduction Visual Basic Programming An Introduction Why Visual Basic? Programming for the Windows User Interface is extremely complicated. Other Graphical User Interfaces (GUI) are no better. Visual Basic provides

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Lex et Yacc, exemples introductifs

Lex et Yacc, exemples introductifs Lex et Yacc, exemples introductifs D. Michelucci 1 LEX 1.1 Fichier makefile exemple1 : exemple1. l e x f l e x oexemple1. c exemple1. l e x gcc o exemple1 exemple1. c l f l l c exemple1 < exemple1. input

More information

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor. Dealing With ASCII ASCII, of course, is the numeric representation of letters used in most computers. In ASCII, there is a number for each character in a message. Max does not use ACSII very much. In the

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

An overview of FAT12

An overview of FAT12 An overview of FAT12 The File Allocation Table (FAT) is a table stored on a hard disk or floppy disk that indicates the status and location of all data clusters that are on the disk. The File Allocation

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment .i.-' `-. i..' `/ \' _`.,-../ o o \.' ` ( / \ ) \\\ (_.'.'"`.`._) /// \\`._(..: :..)_.'// \`. \.:-:. /.'/ `-i-->..

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March

More information

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

PharmaSUG 2015 - Paper QT26

PharmaSUG 2015 - Paper QT26 PharmaSUG 2015 - Paper QT26 Keyboard Macros - The most magical tool you may have never heard of - You will never program the same again (It's that amazing!) Steven Black, Agility-Clinical Inc., Carlsbad,

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016 Master s Degree Course in Computer Engineering Formal Languages FORMAL LANGUAGES AND COMPILERS Lexical analysis Floriano Scioscia 1 Introductive terminological distinction Lexical string or lexeme = meaningful

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Sequences: Strings and Lists Python Programming, 2/e 1 Objectives To understand the string data type and how strings are represented in the computer.

More information