Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

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.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Guide To UNIX Using Linux Third Edition
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
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,
Advanced File Processing
Homework Reading Programming Assignments
1 IPC144 Session 11 The C Programming Language. 2 Objectives To format a #define statement correctly To use a #define statement in a C program To construct.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
Input, Output, and Processing
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
15213 Recitation Section C Introduction Unix and C Playing with Bits Practice Problems Shimin Chen Sept. 9, 2002 Outline.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
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!)
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
CSc 352: Basic C Programming Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Characters and Strings
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CSE 1320 Basics Dr. Sajib Datta
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
Announcements Partial Credit Due Date for Assignment 2 now due on Sat, Feb 27 I always seem to be behind and get tons of daily. If you me and.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Announcements New Due Date for Assignments – Assignments will be due on Fridays now 1.
CS100Lecture 21 Announcements For homework due Thursday, work alone -- do not work in pairs New class location: Olin 155 Office hour oops! Lyn: MW, 11:15-12:15.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
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.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Hank Childs, University of Oregon April 15 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Strings CSCI 112: Programming in C.
Objectives Identify the built-in data types in C++
Revision Lecture
Other Kinds of Arrays Chapter 11
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Lecture 8b: Strings BJ Furman 15OCT2012.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Guide To UNIX Using Linux Third Edition
Data Structures and Programming Techniques
Chapter Four UNIX File Processing.
Introduction to C Topics Compilation Using the gcc Compiler
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Homework Reading Programming Assignments Finish K&R Chapter 1
Introduction to C Topics Compilation Using the gcc Compiler
CSc 352: Elementary “make”
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel there was a mistake, your instructor (that’s me ) Let’s have NO formatting mistakes for Assignment 2! Make sure you name the files EXACTLY as in the specs. (remember Unix cares about case so isFib.c is NOT the same as isfib.c) Use the example programs and diff to make sure your program is correct. 1

What is “make”? make is a Unix tool that simplifies the task of compiling large and complex software projects – the programmer creates a Makefile that speficies: which files depend on which other files what commands to run when a file changes and needs to be (re)compiled – make reads Makefile and runs commands as necessary not such a big deal for small single-source-file programs very helpful when a large number of files involved can be used for many tasks that involve running some commands on files that have changed 2

Example Makefile mayan : mayan.c gcc –Wall mayan.c –o mayan What it means 1.The file mayan is built from the file mayan.c 2.To build mayan from mayan.c, execute this command 3

Makefile structure: rules Makefile mayan : mayan.c gcc –Wall mayan.c –o mayan 4 “target” file(s) the target depends on ( ≥ 0 ) (“prerequisites”) if any of these files is changed, the target must be recompiled. command ( ≥ 0 ) to execute if target is out of date w.r.t. the files it depends on “rule”

How make works Makefile target : prerequisite 1 … prerequisite n command 5 1.if target does not exist: – run command 2.else: if target is older than any of its prerequisites: – run command 3.else: /* (target is up to date) */ – do nothing Simplified Behavior of make

Example 6

Multiple Targets Makefile target1 : prerequisite 1 … prerequisite n command1 target2 : prerequisite 1 … prerequisite m command2 7 1.You can specify the target: make target2 2.If you don’t specify a target, the first target is used. Which target gets “made”

What can commands be? Makefile target : prerequisite 1 … prerequisite n ls -l 8 1.The command doesn't have to be gcc, it can be any Unix command. 2.Here there is a rather silly Makefile that runs ls -l when target doesn't exist or has date older than a prerequisite 3.Notice ls doesn't update target. What happens then if make is run twice in a row?

clean Makefile isFib: isFib.c gcc -Wall -o isFib isFib.c clean: rm -f isFib 9 1.Often a makefile will include a "clean" object to remove files associated with the project 2.Here typing make clean will cause the executable to be deleted. 3.Notice that if there is no file named "clean" in the current directory, the rm command will run everytime you type make clean

Characters and strings A character is of type char (signed or unsigned) – C99 provides support for “wide characters” strings : – an array of characters – terminated by a 0 character (“NUL” : written ‘\0’) – Not a predefined type in C; string operations are provided through libraries C arrays don’t do bound-checking – careless programming can give rise to memory-corruption errors 10

Example of string manipulation 11 declares an array of chars the input analog to printf: “read a value into str” (%s = “string”) print out a string (%s)

More strings… 12 waits for input (from stdin) typed in on keyboard: stdin program output (stdout) end-of-file indicated by typing Ctrl-D

More strings… 13 Oops! this means the program tried to access an illegal memory address

More detail So “strings” are arrays of characters (that end with a NULL (‘\0’)) But what is a character? A character is a byte of data. This can be viewed as a (small) number or as a symbol from the ASCII table. To specify a character in C use single quotes: char c; c = ‘b’; Let’s go to a terminal and experiment 14

So even though characters can be thought of as letters, digits, or symbols, you can also use addition, subtraction, multiplication, etc on them. You can also compare them: ‘A’ < ‘G’ evaluates to true. The uppercase letters and lower case letters run in a sequence. i.e.: ‘c’ + 1 == ‘d’ 15

How can we use this to write a test if a character c is a capitol letter? 16

How can we use this to write a test if a character c is a upper case letter? if (c >= ‘A’ && c <= ‘Z’) { // if c is an uppercase letter then we go here } Let’s go to the terminal and write a function to convert all the lowercase letters of a string to upper case. 17

The completed program 18