# today cs3157-fall2002-sklar-lect05 1

Size: px
Start display at page:

Transcription

1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1

2 logical operators (1) in C are the same as in Java meaning C operator AND && OR NOT! since there are no boolean types in C, these are mainly used to connect clauses in if and while statements remember that non-zero zero cs3157-fall2002-sklar-lect05 2

3 logical operators (2) exercise: what is the output of the following code fragment? int n = 12345, m = 0; printf( "n and n=[%d]\n",n && n); printf( "n or n=[%d]\n",n n); printf( "not n=[%d]\n",!n ); printf( "n and m=[%d]\n",n && m); printf( "n or m=[%d]\n",n m); printf( "not m=[%d]\n",!m ); cs3157-fall2002-sklar-lect05 3

4 logical operators (3) there are also bitwise operators in C, in which each bit is an operand: meaning C operator bitwise AND & bitwise OR example: int a = 8; /* this is 1000 in base 2 */ int b = 15; /* this is 1111 in base 2 */ a & b 1000 (=8) & 1111 (=15) 1000 (=8) a b 1000 (=8) 1111 (=15) 1111 (=15) cs3157-fall2002-sklar-lect05 4

5 logical operators (4) exercise: what is the output of the following code fragment? int a = 12, b = 7; printf( "a && b = %d\n",a && b ); printf( "a b = %d\n",a b ); printf( "a & b = %d\n",a & b ); printf( "a b = %d\n",a b ); cs3157-fall2002-sklar-lect05 5

6 random numbers (1) with computers, nothing is random (even though it may seem so at times...) there are two steps to using random numbers in C: 1. seeding the random number generator 2. generating random number(s) standard library function: #include <stdlib.h> seed function: srand( time ( NULL )); random number function returns a number between 0 and RAND_MAX (which is int i = rand(); ) cs3157-fall2002-sklar-lect05 6

7 random numbers (2) #include <stdio.h> #include <stdlib.h> #include <time.h> int main( void ) { int r; srand( time ( NULL )); r = rand() % 100; printf( "pick a number between 0 and \n" ); printf( "was %d your number?", r ); } cs3157-fall2002-sklar-lect05 7

8 character handling functions (1). character handling library #include <ctype.h> digit recognition functions (bases 10 and 16) alphanumeric character recognition case recognition/conversion character type recognition these are all of the form: int isdigit( int c ); where the argument c is declared as an int, but it is intepreted as a char so if c = 0 (i.e., the ASCII value 0, index=48), then the function returns true (non-zero int) but if c = 0 (i.e., the ASCII value NULL, index=0), then the function returns false (0) cs3157-fall2002-sklar-lect05 8

9 character handling functions (2). digit recognition functions (bases 10 and 16) int isdigit( int c ); returns true (i.e., non-zero int) if c is a decimal digit (i.e., in the range ); returns 0 otherwise int isxdigit( int c ); returns true (i.e., non-zero int) if c is a hexadecimal digit (i.e., in the range 0.. 9, A.. F ); returns 0 otherwise cs3157-fall2002-sklar-lect05 9

10 character handling functions (3). alphanumeric character recognition int isalpha( int c ); returns true (i.e., non-zero int) if c is a letter (i.e., in the range A.. Z, a.. z ); returns 0 otherwise int isalnum( int c ); returns true (i.e., non-zero int) if c is an alphanumeric character (i.e., in the range A.. Z, a.. z, ); returns 0 otherwise cs3157-fall2002-sklar-lect05 10

11 character handling functions (4). case recognition int islower( int c ); returns true (i.e., non-zero int) if c is a lowercase letter (i.e., in the range a.. z ); returns 0 otherwise int isupper( int c ); returns true (i.e., non-zero int) if c is an uppercase letter (i.e., in the range A.. Z ); returns 0 otherwise case conversion int tolower( int c ); returns the value of c converted to a lowercase letter (does nothing if c is not a letter or if c is already lowercase) int toupper( int c ); returns the value of c converted to an uppercase letter (does nothing if c is not a letter or if c is already uppercase) cs3157-fall2002-sklar-lect05 11

12 character handling functions (5). character type recognition int isspace( int c ); returns true (i.e., non-zero int) if c is a space; returns 0 otherwise int iscntrl( int c ); returns true (i.e., non-zero int) if c is a control character; returns 0 otherwise int ispunct( int c ); returns true (i.e., non-zero int) if c is a punctuation mark; returns 0 otherwise int isprint( int c ); returns true (i.e., non-zero int) if c is a printable character; returns 0 otherwise int isgraph( int c ); returns true (i.e., non-zero int) if c is a graphics character; returns 0 otherwise cs3157-fall2002-sklar-lect05 12

13 character handling functions (6). exercise: start with the following code fragment that loops through the extended ASCII character set (0..255) and prints out each index and each ASCII value: int i; for ( i=0; i<256; i++ ) { printf( "%d %c\n",i,i ); } make this into a program call each ctype function shown on the previous slides that start with is and print out the return values then you can see which characters are printable, graphics, etc. cs3157-fall2002-sklar-lect05 13

14 file I/O (1). file handling involves three steps: 1. opening the file 2. reading from and/or writing to the file 3. closing the file files in C are sequential access think of it as a cursor that sits at a position in the file with each read and write operation, you move that cursor s position in the file the last position in the file is called the end-of-file and is typically written as: <EOF> all the functions described on the next few slides are defined in the <stdio.h> header file cs3157-fall2002-sklar-lect05 14

15 file I/O (2). opening files FILE *fopen( const char *filename, const char *mode ); filename is a string containing the name of the file you want to open; this file is in the current working directory or else you have to include a full path specification mode is one of the following: mode meaning cursor position create file? r read only beginning of file no r+ read/write beginning of file no w write only beginning of file yes w+ read/write beginning of file yes a write only end of file no a+ read/write end of file no the last column indicates whether the file is created if it does not exist this is only done with the w modes the function returns a value of type FILE *, which is a file pointer (we ll talk about pointers later today), or NULL if there is an error cs3157-fall2002-sklar-lect05 15

16 file I/O (3). reading from and writing to files these functions are just like printf and scanf, except that instead of writing to the screen and reading from the keyboard, they write to and read from a file for writing to a file: int fprintf( FILE *fp, const char *format /*, args...*/ ); this function returns the number of bytes written fp is the file pointer of the file you are writing to for reading from a file: int fscanf( FILE *fp, const char *format /*, args...*/ ); this function returns the number of bytes read fp is the file pointer of the file you are reading from cs3157-fall2002-sklar-lect05 16

17 file I/O (4). closing files int close( FILE *fp ); fp is the pointer to the file you want to close (the value returned from a previous call to fopen) cs3157-fall2002-sklar-lect05 17

18 strings (1). storing multiple characters in a single variable data type is still char BUT it has a length last character the is terminator: \0, aka NULL string constants are surrounded by double quotes: " example: char s[6] = "ABCDE"; cs3157-fall2002-sklar-lect05 18

19 strings (2). example: char s[6] = "ABCDE"; storage looks like this: A B C D E 0 so with strings, you really only access the values stored at indeces since the value stored at is always 0 through, cs3157-fall2002-sklar-lect05 19

20 strings (3). printing strings format sequence: %s example: #include <stdio.h> int main( void ) { char str[6] = "ABCDE"; printf( "str = %s\n", str ); } /* end of main() */ output: ABCDE cs3157-fall2002-sklar-lect05 20

21 strings (4). string handling library #include <string.h> functions include: int strlen( char *s ); this function returns the number of characters in s; note that this is NOT the same thing as the number of characters allocated for the string array int strcmp( const char *s1, const char *s2 ); This function returns an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 respectively. The sign of a non-zero return value is determined by the sign of the difference between the values of the first pair of bytes that differ in the strings being compared. for more information and more string functions, do: unix\$ man strcmp cs3157-fall2002-sklar-lect05 21

22 arrays (1). a string is an array of characters an array is a regular grouping or ordering a data structure consisting of related elements of the same data type in C, an array has a length associated with it arrays need: data type name length length can be determined: statically at compile time e.g., char str1[10]; dynamically at run time e.g., char *str2; cs3157-fall2002-sklar-lect05 22

23 arrays (2). defining a variable is called allocating memory to store that variable defining an array means allocating memory for a group of bytes, i.e., assigning a label to the first byte in the group individual array elements are indexed starting with ending with indeces follow array name, enclosed in square brackets ([ ]) e.g., arr[25] cs3157-fall2002-sklar-lect05 23

24 array (3). character array example #include <stdio.h> #define MAX 6 int main( void ) { char str[max] = "ABCDE"; int i; for ( i=0; i<max-1; i++ ) { printf( "%c", str[i] ); } printf( "\n" ); } /* end of main() */ cs3157-fall2002-sklar-lect05 24

25 arrays (4). integer array example #include <stdio.h> #define MAX 6 int main( void ) { int arr[max] = { -45, 6, 0, 72, 1543, 62 }; int i; for ( i=0; i<max; i++ ) { printf( "%d", arr[i] ); } printf( "\n" ); } /* end of main() */ cs3157-fall2002-sklar-lect05 25

26 pointers (1). variables that contain memory addresses as their values other data types we ve learned about in C use direct addressing pointers facilitate indirect addressing declaring pointers: pointers indirectly address memory where data of the types we ve already discussed is stored (e.g., int, char, float, etc.) declaration uses asterisks (*) to indicate a pointer to a memory location storing a particular data type example: int *count; float *avg; cs3157-fall2002-sklar-lect05 26

27 pointers (2). ampersand & is used to dereference a pointer it says: return the address of the variable argument example: int count = 12; int *countptr = &count; &count returns the address of count and stores it in the pointer variable countptr a picture: countptr count 12 cs3157-fall2002-sklar-lect05 27

28 pointers (3). here s another example: int i = 3, j = -99; int count = 12; int *countptr = &count; and here s what the memory looks like: variable name memory location value count 0xbffff4f0 12 i 0xbffff4f4 3 j 0xbffff4f countptr 0xbffff600 0xbffff4f0... cs3157-fall2002-sklar-lect05 28

29 pointers (4). an array is some number of contiguous memory locations an array definition is really a pointer to the starting memory location of the array and pointers are really integers so you can perform integer arithmetic on them e.g., +1 increments a pointer, -1 decrements you can use this to move from one array element to another cs3157-fall2002-sklar-lect05 29

30 pointers (5). #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int i, *j, arr[5]; srand( time ( NULL )); for ( i=0; i<5; i++ ) arr[i] = rand() % 100; printf( "arr=%p\n",arr ); for ( i=0; i<5; i++ ) { printf( "i=%d arr[i]=%d &arr[i]=%p\n",i,arr[i],&arr[i] ); } j = &arr[0]; printf( "\nj=%p *j=%d\n",j,*j ); j++; printf( "after adding 1 to j:\n j=%p *j=%d\n",j,*j ); } cs3157-fall2002-sklar-lect05 30

31 pointers (6). and the output is... arr=0xbffff4f0 i=0 arr[i]=29 &arr[i]=0xbffff4f0 i=1 arr[i]=8 &arr[i]=0xbffff4f4 i=2 arr[i]=18 &arr[i]=0xbffff4f8 i=3 arr[i]=95 &arr[i]=0xbffff4fc i=4 arr[i]=48 &arr[i]=0xbffff500 j=0xbffff4f0 *j=29 after adding 1 to j: j=0xbffff4f4 *j=8 cs3157-fall2002-sklar-lect05 31

32 today s example. The tendency of people to focus on the meaning of sentences influences their ability to notice some of the obvious features. exercise: write a program to count the number of f s in the above. write a program to count the total number of characters write a program to count the total number of words write a program to write this to a file write a program to read this from a file cs3157-fall2002-sklar-lect05 32

### cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

### arrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.

topics: arrays pointers arrays of objects resources: cis15 advanced programming techniques, using c++ summer 2008 lecture # V.1 some of this lecture is covered in parts of Pohl, chapter 3 arrays review

### Fundamentals of Programming. Lecture 11: C Characters and Strings

1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

### Chapter 8 - Characters and Strings

1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

### C: How to Program. Week /May/28

C: How to Program Week 14 2007/May/28 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions

### C Libraries. Bart Childs Complementary to the text(s)

C Libraries Bart Childs Complementary to the text(s) 2006 C was designed to make extensive use of a number of libraries. A great reference for student purposes is appendix B of the K&R book. This list

### Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

### Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

### C mini reference. 5 Binary numbers 12

C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

### Structured programming

Exercises 10 Version 1.0, 13 December, 2016 Table of Contents 1. Strings...................................................................... 1 1.1. Remainders from lectures................................................

### Scientific Programming in C V. Strings

Scientific Programming in C V. Strings Susi Lehtola 1 November 2012 C strings As mentioned before, strings are handled as character arrays in C. String constants are handled as constant arrays. const char

### SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

### Characters and Strings

Characters and Strings 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Character constants A character in single quotes,

### Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and

### Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Looping Forward Through the Characters of a C String A lot of C string algorithms require looping forward through all of the characters of the string. We can use a for loop to do that. The first character

### Chapter 7 C Pointers

Chapter 7 C Pointers Objectives of This Chapter Definition and Operations with Pointers Using Pointers to pass arguments as call by reference call. Using Pointers to deal with arrays and strings. Character

### Strings and Library Functions

Unit 4 String String is an array of character. Strings and Library Functions A string variable is a variable declared as array of character. The general format of declaring string is: char string_name

### Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

### A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

### Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,

### C PROGRAMMING. Characters and Strings File Processing Exercise

C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes

### C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

CS 2060 Variables Variables are statically typed. Variables must be defined before they are used. You only specify the type name when you define the variable. int a, b, c; float d, e, f; char letter; //

### Arrays, Strings, & Pointers

Arrays, Strings, & Pointers Alexander Nelson August 31, 2018 University of Arkansas - Department of Computer Science and Computer Engineering Arrays, Strings, & Pointers Arrays, Strings, & Pointers are

### Contents. Preface. Introduction. Introduction to C Programming

c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

### Approximately a Test II CPSC 206

Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and

### Appendix A Developing a C Program on the UNIX system

Appendix A Developing a C Program on the UNIX system 1. Key in and save the program using vi - see Appendix B - (or some other editor) - ensure that you give the program file a name ending with.c - to

### UNIT-I Input/ Output functions and other library functions

Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

### Computer Programming

Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 1 Outline Functions Structure of a function

### Chapter 10 Characters, Strings, and the string class

Standard Version of Starting Out with C++, 4th Edition Chapter 10 Characters, Strings, and the string class Copyright 2003 Scott/Jones Publishing Topics 10.1 Character Testing 10.2 Character Case Conversion

### CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

### CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012 TOPICS TODAY Characters & Strings in C Structures in C CHARACTERS & STRINGS char type C supports the char data type

### Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

### LESSON 4. The DATA TYPE char

LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

### Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions

Outline Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein Functions Structure of a function Function invocation Parameter passing Functions as parameters Variable

### Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

### Announcements. Strings and Pointers. Strings. Initializing Strings. Character I/O. Lab 4. Quiz. July 18, Special character arrays

Strings and Pointers Announcements Lab 4 Why are you taking this course? Lab 5 #, 8: Reading in data from file using fscanf Quiz Quiz Strings Special character arrays End in null character, \ char hi[6];

### Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

### Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape

### CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

CS113: Lecture 7 Topics: The C Preprocessor I/O, Streams, Files 1 Remember the name: Pre-processor Most commonly used features: #include, #define. Think of the preprocessor as processing the file so as

### C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

### advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

### CS3157: Advanced Programming. Lecture #2 May 30 Shlomo Hershkop

CS3157: Advanced Programming Lecture #2 May 30 Shlomo Hershkop shlomo@cs.columbia.edu Overview Today: More C Basics Debugging process Intro CGI Background Integrating c Some Shell Programming Keep in touch

### Strings and Stream I/O

Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?

### Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character

### Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. A Taste of C. Agenda.

Princeton University Computer Science 217: Introduction to Programming Systems Goals of this Lecture A Taste of C C Help you learn about: The basics of C Deterministic finite-state automata (DFA) Expectations

### Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10

### Contents. A Review of C language. Visual C Visual C++ 6.0

A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

### cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is

### B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

### Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

EE209: C Examples 1 Reminder Sign up for ee209 mailing list If you haven t received any email from ee209 yet Follow the link from our class homepage Precept 7:00-8:15pm, every Wednesday 창의학습관 (Creative

### Goals of this Lecture

A Taste of C C 1 Goals of this Lecture Help you learn about: The basics of C Deterministic finite state automata (DFA) Expectations for programming assignments Why? Help you get started with Assignment

### Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

### Today s Learning Objectives

Today s Learning Objectives 15-123 Systems Skills in C and Unix We will Review ints and modular arithmetic Learn basic Data types and Formats How Conditionals and loops work How Arrays are defined, accessed,

### Fundamentals of Computer Programming Using C

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

### Exercise 1.1 Hello world

Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

### Chapter 10: Characters, C- Strings, and More About the string Class

Chapter 10: Characters, C- Strings, and More About the string Class 10.1 Character Testing Character Testing require cctype header file FUNCTION isalpha isalnum isdigit islower isprint ispunct isupper

### Chapter 10: Character Testing. From Program Character Case Conversion 8/23/2014. Character Testing. Character Case Conversion

Chapter 10: Characters, C- Strings, and More About the string Class 10.1 Character Testing Character Testing Requires cctype header file From Program 10-1 FUNCTION isalpha isalnum isdigit islower isprint

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

### Section 3: Library Functions

Section 3: Library Functions This section of the manual describes the functions available to programs from the standard Xinu library. C programmers will recognize some of the C library functions (esp.

### Computer Language. It is a systematical code for communication between System and user. This is in two categories.

ComputerWares There are 3 types of Computer wares. 1. Humanware: The person, who can use the system, is called 'Human Ware ". He is also called as "User". Users are in two types: i. Programmer: The person,

### C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations

55:017, Computers in Engineering C Pointers C Pointers Powerful C feature but challenging to understand Some uses of pointers include Call by reference parameter passage Dynamic data structures Data structures

### Intermediate Programming, Spring 2017*

600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

### OBJECTIVE QUESTIONS: Choose the correct alternative:

OBJECTIVE QUESTIONS: Choose the correct alternative: 1. Function is data type a) Primary b) user defined c) derived d) none 2. The declaration of function is called a) function prototype b) function call

### Introduction to string

1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

### ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

### Technical Questions. Q 1) What are the key features in C programming language?

Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility

### Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

### COMP26120: Pointers in C (2018/19) Lucas Cordeiro

COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11

### ch = argv[i][++j]; /* why does ++j but j++ does not? */

CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and

### C programming basics T3-1 -

C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

### Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

### Euclid s algorithm, 133

Index A Algorithm computer instructions, 4 data and variables, 5 develop algorithm, 6 American Standard Code for Information Interchange (ASCII) codes, 141 definition, 142 features, 142 Arithmetic expressions

### Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point

### Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

Jagannath Institute of Management Sciences Lajpat Nagar BCA II Sem C Programming UNIT I Pointers: Introduction to Pointers, Pointer Notation,Decalaration and Initialization, Accessing variable through

### Module 4 Arrays, Strings, and Pointers

Module 4 Arrays, Strings, and Pointers Table of Contents CRITICAL SKILL 4.1: Use one-dimensional arrays... 2 CRITICAL SKILL 4.2: Two-Dimensional Arrays... 6 CRITICAL SKILL 4.3: Multidimensional Arrays...

### Topics so far. Review. scanf/fscanf. How data is read 1/20/2011. All code handin sare at /afs/andrew/course/15/123/handin

15-123 Effective Programming in C and Unix Announcements SL2 is due Thursday 1/20 midnight Complete the Academic Honesty Form in class All code downloads are from /afs/andrew/course/15/123/download All

### I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

### Princeton University Computer Science 217: Introduction to Programming Systems. A Taste of C

Princeton University Computer Science 217: Introduction to Programming Systems A Taste of C C 1 Goals of this Lecture Help you learn about: The basics of C Deterministic finite-state automata (DFA) Expectations

### Pointers. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Pointers Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline 7.1 Introduction 7.2 Pointer Variable Definitions and Initialization 7.3 Pointer

### C Programming. Unit 9. Manipulating Strings File Processing.

Introduction to C Programming Unit 9 Manipulating Strings File Processing skong@itt-tech.edu Unit 8 Review Unit 9: Review of Past Material Unit 8 Review Arrays Collection of adjacent memory cells Each

### Chapter 10: Characters, C- Strings, and More About the string Class Character Testing

Chapter 10: Characters, C- Strings, and More About the string Class 1 10.1 Character Testing 2 Character Testing require cctype header file FUNCTION isalpha isalnum isdigit islower isprint ispunct isupper

### Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

### Programming in C. Part 1: Introduction

Programming in C Part 1: Introduction Resources: 1. Stanford CS Education Library URL: http://cslibrary.stanford.edu/101/ 2. Programming in ANSI C, E Balaguruswamy, Tata McGraw-Hill PROGRAMMING IN C A

### Kurt Schmidt. October 30, 2018

to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

### Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

Introduction to Algorithms and Data Structures Lecture 6 - Stringing Along - Character and String Manipulation What are Strings? Character data is stored as a numeric code that represents that particular

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### System Design and Programming II

System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 10 Characters, Strings, and the string Class Character Testing The C++ library

### 211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case

Overview of Today s Lecture Lecture 2: Character Input/Output in C Prof. David August COS 217 http://www.cs.princeton.edu/courses/archive/fall07/cos217/ Goals of the lecture o Important C constructs Program

### C Examples. Goals of this Lecture. Overview of this Lecture

C Examples 1 Goals of this Lecture Help you learn about: The fundamentals of C Overall program structure, control statements, character I/O functions Deterministic finite state automata (DFA) Expectations

### File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

### SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator 0 Problem 0 number bases Visit the website www.cleavebooks.co.uk/scol/calnumba.htm

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

### C Programming Multiple. Choice

C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980