Administrative things

Slides:



Advertisements
Similar presentations
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Basic Input/Output and Variables Ethan Cerami New York
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Computer Science 210 Computer Organization Introduction to C.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
INTRODUCTION TO C PROGRAMMING LANGUAGE Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
How to start Visual Studio 2008 or 2010 (command-line program)
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
1 Lecture03: Control Flow 9/24/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
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.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Lecture 3: Getting Started & Input / Output (I/O)
Lecture2.
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
CSE 220 – C Programming C Fundamentals.
A bit of C programming Lecture 3 Uli Raich.
ECE Application Programming
Administrative things
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
EECE.2160 ECE Application Programming
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Getting Started with C.
Lecture2.
Administrative things
Visit for more Learning Resources
Input and Output Lecture 4.
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.
Computer Science 210 Computer Organization
Formatted Input/Output
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Introduction to CS Your First C Programs
Introduction to C Topics Compilation Using the gcc Compiler
Lecture3.
Your first C and C++ programs
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Formatted Input/Output
Conversion Check your class notes and given examples at class.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
EECE.2160 ECE Application Programming
Formatted Input/Output
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
EECE.2160 ECE Application Programming
Administrative things
EECE.2160 ECE Application Programming
Presentation transcript:

Lecture02: Overview of C 2/29/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C

Administrative things Textbook is optional C is a simple language, no need for a thick textbook (homework exercises) Slides will cover it TimeString (TA) hour work Friday 10:30 ~ 11:30 Assignment #1 is on the course webpage due next week. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Structure of a C Program Overall Program <some pre-processor directives> <global declarations> <global variables> <functions> Functions <function header> <local declarations> <statements> Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

main.c: Hello World #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

CodeBlocks: Compile and Run Run CodeBlocks Create a new project File → New → Project Select “Console application” Click C → Next Type in Project title: (e.g., “hello”) Click finish Open and edit the main.c File → Open Find “main.c” Compile and run Build → Build and Run Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

What Happened? Compile (Build → Build) Compile “main.c” to machine code named “hello.exe” Run (Build → Run) Execute the program “hello.exe” main.c (Hello World) include <stdio.h> /* printf() is declared in this header file. */ int main() /* Main point of execution */ { printf("Hello World\n"); /* Output “Hello World” to console */ return 0; /* Tell OS the program terminates normally */ } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

main.c: Variables #include <stdio.h> int main() { int a, b, c; c = a * b; printf("a = %d b = %d c = %d\n", a, b, c); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

main.c: CommandLineArgs #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int n, m; n = atoi(argv[1]); m = atoi(argv[2]); printf("Argument 1: %d\nArgument 2: %d\n", n, m); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

More on printf printf(format string, val1, val2); Examples format string can include placeholders that specify how the arguments val1, val2, etc. should be formatted %c : format as a character %d : format as an integer %f : format as a floating-point number %% : print a % character Examples double f = 0.95; printf("f = %f%%\n", f * 100); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Even more on printf Placeholders can also specify widths and precisions %10d : add spaces to take up at least 10 characters %010d : add zeros to take up at least 10 characters %.2f : print only 2 digits after decimal point %5.2f : print 1 decimal digit, add spaces to take up 5 chars Examples int i = 95; double f = 0.95; printf("i = %d\n", i); printf("i = %10d\n", i); printf("i = %010d\n", i); printf("f = %f\n", f); printf("f = %.2f%%\n", f * 100); printf("f = %10.2f%%\n", f * 100); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Warning about printf printf is powerful, but potentially dangerous What does this code output? int i = 90; double f = 3; printf("f = %f i = %d\n", f); printf("f = %f\n", f, i); printf("i = %d f = %f\n", f, i); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

main.c: Scanf #include <stdio.h> int main() { int i; double f; scanf("%d", &i); scanf("%lf", &f); printf("Integer: %d Float: %2.2f\n", i, f); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

In-Class Exercise Write a program that calculates travel reimbursement for a pizza delivery person at a rate of NT$6.97 per kilometer. Your program should interact with the user in the following manner: (It is okay not to get the program right the first time. Look at the compilation errors and fix them.) KILOMETER REIMBURSEMENT CALCULATOR Enter beginning odometer readings=> 13505.2 Enter ending odometer reading=> 13810.6 You traveled 305.4 kilometers. At $6.97 per kilometer, Your reimbursement is $2128.63 Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?