CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
TDBA66, VT-03 Lecture - Ch. 21 A complete C-program Display Fig. 2.1 and comment on different things such as Preprocessor directives Header files Identifiers.
41 A Depth Program #include int main(void) { int inches, feet, fathoms; //declarations fathoms = 7; feet = 6 * fathoms; inches = 12 * feet; printf(“Wreck.
1 Review of Class on Oct Outline of Chapter 4  How to write a function?  Function Prototypes  Function Invocation  Function Definition  The.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
PHYS 2020 Basic C An introduction to writing simple but useful programs in C In these lectures I will take you through the basics of C, but you will need.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
CMSC 104, Version 8/061L15Switch.ppt The switch Statement Topics Multiple Selection switch Statement char Data Type and getchar( ) EOF constant Reading.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Yu Yuanming CSCI2100B Data Structures Tutorial 3
CSCI 171 Presentation 1. Computer Software System Software –Operating systems –Utility programs –Language compilers Application Software.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
Scanf Reads in information from the keyboard Examples –scanf(“%d”, &number); –scanf(“%d%d”, &value1, &value2); WARNINGS! –Don’t forget the & (address of)
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
How to start Visual Studio 2008 or 2010 (command-line program)
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Introduction to C Programming CE Lecture 4 Further Control Structures in C.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Assignment Operators = +=-= *= /=%= Statement Equivalent Statement a = a + 2 ;a += 2 ; a = a - 3 ;a -= 3 ; a = a * 2 ;a *= 2 ; a = a / 4 ; a /= 4 ; a =
The switch Statement.  Occasionally, an algorithm will contain a series of decisions in which a variable or expression is tested separately for each.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CMSC 104, Version 9/011 The switch Statement Topics Multiple Selection switch Statement char Data Type and getchar( ) EOF constant Reading Section 4.7,
Computer Programming Control Structure
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
CSC Programming for Science Lecture 8: Character Functions.
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Data Types and Input Output in C. Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d.
CS 108 Computing Fundamentals Notes for Tuesday, March 22, 2016.
Dr. Sajib Datta Sep 8,  char type technically is an integer type  Computer uses numeric codes to represent characters, and store characters.
Lecture2.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
Strings (Continued) Chapter 13
Command Line Arguments
Chapter 2 Overview of C.
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.
Loops The loop blocks you've used in Scratch can all be recreated in C! Loops allow for the repetition of code until a condition is met. There are three.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Introduction to CS Your First C Programs
CSCE 206 Lab Structured Programming in C
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
Lecture3.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to Computer Organization & Systems
CSCE 206 Lab Structured Programming in C
UMBC CMSC 104 – Section 01, Fall 2016
CSCE 206 Lab Structured Programming in C
Presentation transcript:

CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers

Getting started ● Please log in to the computer, click on the startup menu (located in bottom left corner) ● Select “Utilities” -> “Kate” to open a text editor

Running our program ● We need to compile our C program using the compiler called cc ● The compiler then outputs an executable file which will run our program, usually called a.out ● To run it, open up a Konsole (the little black screen icon at the bottom), type “cc filename.c”, then type “./a.out” at a command prompt

Recap ● Numbers - int, float ● Output – printf ● Input - scanf ● If-else statements ● While loops ● Characters - char

Characters ● The data type char stores a single character ● Each character is actually represented as a number, just like with ASCII ● To read or write a character variable, use %c

Basic char program #include main(void) { char letter; printf(“Enter a character:”); scanf(“%c”,&letter); printf(“You entered %c”, letter); return 0; }

Fun with char #include main(void) { char letter; \\initialize letter to be a character \\Read in a character printf(“Enter a character:”); scanf(“%c”, &letter); \\Print out the character and its associated number printf(“The character you entered is %c \n”, letter); printf(“Its C number is %d”, letter); return 0; }

Char tricks #include main(void) { char letter; int number; //Prompt user to enter a character printf("Enter a letter:"); scanf("%c", &letter); //Find the next letter in the alphabet and print it number = letter; number = number + 1; printf("The next letter is %c\n", number); return 0; }

A shortcut ● The c command “getchar()” reads the next character from the input ● So letter = getchar(); is equivalent to scanf(“%c”, &letter);

Count the length of a message #include main(void) { char ch; int length = 0; //Prompt the user for a message //Read the first character of the message //while loop to count how the message is //print length of message return 0; }