Introduction to C Programming Ray Lauff Temple University Computer Science v2.0
|
|
- Marcus Lynch
- 6 years ago
- Views:
Transcription
1 Introduction to C Programming Ray Lauff Temple University Computer Science v2.0 NOTE: Not all the material covered in class is included in this slide deck. These slides are not meant to be used as a stand-alone learning tool. You are still responsible for ALL material covered. Get the notes from a classmate.
2 What is a string?
3 What is a string? A string is a collection of zero or more characters followed by the ASCII NUL character. '\0'
4 What is a character array?
5 What is a character array? A character array is a variable of type char that represents one or more characters. char my_char_array[ 400 ];
6 1. C will create strings for you automatically every time you use double quotes in source code. True or False?
7 1. C will create strings for you automatically every time you use double quotes in source code. True or False? char name[ 20 ] = "Patty Programmer";
8 2. Given: puts( "My brain is full!!!" ); The argument to the puts() function is a string. True or False?
9 3. Given: printf( "%s\n", "That does not compute." ); Both arguments to the printf() function are strings. True or False?
10 4. The puts( ) statement can only take one argument, and it must be a string. True or False?
11 puts() and printf() The puts( ) function ONLY accepts one string argument. The printf( ) function ALWAYS takes one string argument as the first parameter to the function. All the other arguments to printf( ) are dependent on this first argument. The other arguments to printf( ) to match up with the placeholders. Those other arguments can be of all different types, and are always passed by value to printf( ). Is printf( ) special or what??
12 5. The sprintf( ) function allows you to write strings to the screen just like the printf( ) function. True or False?
13 sprintf( ) Writes output to a string, not to the screen. The string is the first parameter to the function. This is the prototype for sprintf( ), which can be found in stdio.h. int sprintf(char * restrict str, const char * restrict format,...);
14 6. sprintf( ) should be used instead of snprintf( ) because it allows you to output the data to files as well as to strings. True or False?
15 snprintf( ) snprintf( ) is preferred because it limits the size of the data that goes into the string, preventing overindexing. const int bufsize = 80; char buffer[ bufsize ]; int yum = 700; char name[100] = "Big Rock Candy Mountain"; snprintf( buffer, bufsize, "%d %s", yum, name );
16 snprintf( ) This is the prototype for snprintf( ), which is found in stdio.h. int snprintf(char *str, size_t size, const char *format,...); Only the first three parameters are required. The placeholders in the format determine how many additional parameters are required on the snprintf( ) invocation.
17 Choose the BEST answer! 7. The primary difference between an array and a string is a) the length of an array is always known, but the length of a string varies. b) multiple strings can be stored in an array, but only one can be in a string. c) sizeof a will always return the number of elements in the array a. d) strings always end with a sentinel value where arrays may or may not. e) arrays can hold strings, but strings can't hold arrays. f) a string can't be passed to a function, but an array can.
18 Choose the BEST answer! 8. The length of a string can be determined with a) sizeof b) strlen c) strnlen d) sizeof / sizeof one of the elements
19 strlen and sizeof Remember that strlen returns the number of characters in a string. char name[ ] = "Tan"; strlen( name ); // will return 3
20 strlen and sizeof sizeof returns the space occupied by a variable. char name[ ] = "Tan"; sizeof name; // will return 4
21 strlen and sizeof sizeof is an operator and is "baked in" to C as part of the language. strlen is a function with a prototype provided in the string.h header. extern size_t strlen ( const char * s);
22 strlen and sizeof size_t strlen ( const char * s); What is the return type of this function prototype?
23 strlen and sizeof size_t strlen ( const char * s); size_t is a type suitable for representing the amount of space a given thing requires, expressed in characters. It is always going to be zero or a positive integer. It is the return type of both strlen and sizeof. It is a 'unsigned long integer'.
24 strlen and sizeof char name[ ] = "Tan"; unsigned long stringlen = strlen( name ); unsigned long sizelen = sizeof name; printf( "The length of the string is %lu.\n", stringlen ); printf( "The memory spaced used is %lu.\n", sizelen );
25 strlen and sizeof char name[ ] = "Tan"; unsigned long stringlen = strlen( name ); unsigned long sizelen = sizeof name; printf( "The length of the string is %lu.\n", stringlen ); printf( "The memory spaced used is %lu.\n", sizelen ); The length of the string is 3. The memory spaced used is 4.
26 9. char buf[ 12 ] = "Temple"; The number of elements in this array which have been initialized is a) 0 b) 6 c) 7 d) 8 e) 9 f) 11 g) 12
27 10. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf );
28 10. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf ); Temple
29 11. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%c\n", buf[0] );
30 11. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%c\n", buf[0] ); T
31 12. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%c\n", *buf );
32 12. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%c\n", *buf ); T
33 13. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%d\n", buf[0] );
34 13. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%d\n", buf[0] ); 84
35 14. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf[ 4 ] );
36 14. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf[ 4 ] ); Segmentation Fault! Core dump.
37 15. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf + 4 );
38 15. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf + 4 ); le
39 Note Doing the math with a pointer, as with char buf[ 12 ] = "Temple"; printf( "%s\n", buf + 4 ); can also be written as printf( "%s\n", &(buf[ 4 ])); or you can print just a single character as with printf( "%c\n", buf[ 4 ] );
40 16. What gets printed by the following? char buf[ 12 ] = "Temple"; int i = 3; while ( buf[i]!= '\0' ) putchar( buf[ i++ ] );
41 16. What gets printed by the following? char buf[ 12 ] = "Temple"; int i = 3; while ( buf[i]!= '\0' ) putchar( buf[ i++ ] ); ple
42 17. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf + 3 );
43 17. What gets printed by the following? char buf[ 12 ] = "Temple"; printf( "%s\n", buf + 3 ); ple
44 18. What gets printed by the following? char buf[ 12 ] = "Temple"; int i; for ( i = 0; buf[ i ]!= '\0'; i++ ) if ( buf[ i ] == 'e' buf[ i ] == 'l' ) putchar( buf[ i ] );
45 18. What gets printed by the following? char buf[ 12 ] = "Temple"; int i; for ( i = 0; buf[ i ]!= '\0'; i++ ) if ( buf[ i ] == 'e' buf[ i ] == 'l' ) putchar( buf[ i ] ); ele
46 19. What gets printed by the following? char buf[ 12 ] = "Temple"; int i; for ( i = 0; buf[ i ]!= '\0'; i++ ) if ( buf[ i ] == 'e' buf[ i ] == 'l' ) putchar( buf[ i - 1 ] );
47 19. What gets printed by the following? char buf[ 12 ] = "Temple"; int i; for ( i = 0; buf[ i ]!= '\0'; i++ ) if ( buf[ i ] == 'e' buf[ i ] == 'l' ) putchar( buf[ i - 1 ] ); Tpl
48 20. What is in the variable hold? char buf[ 12 ] = "Temple"; char hold[ 100 ]; int i; int j = strlen( buf ); hold[ j-- ] = '\0'; for ( i = 0; buf[ i ]!= '\0'; i++ ) hold[ j-- ] = buf[ i ];
49 20. What is in the variable hold? char buf[ 12 ] = "Temple"; char hold[ 100 ]; int i; int j = strlen( buf ); hold[ j-- ] = '\0'; for ( i = 0; buf[ i ]!= '\0'; i++ ) hold[ j-- ] = buf[ i ]; The variable hold now contains: e l p m e T \0 [0] [1] [2] [3] [4] [5] [6]
50 21. What gets printed by the following? char *nicks[ ] = { }; "Crash Override", "Acid Burn", "Zero Cool", int i; int n = sizeof nicks / sizeof nicks[0]; for ( i = 0; i < n; i++ ) printf( "%c\n", nicks[ i ][ 1 ] );
51 21. What gets printed by the following? char *nicks[ ] = { }; "Crash Override", "Acid Burn", "Zero Cool", int i; int n = sizeof nicks / sizeof nicks[0]; for ( i = 0; i < n; i++ ) printf( "%c\n", nicks[ i ][ 1 ] ); r c e
52 22. What gets printed by the following? char *nicks[ ] = { "Crash Override", "Acid Burn", "Zero Cool", }; int i, j; int n = sizeof nicks / sizeof nicks[0]; for ( i = 0; i < n; i++ ) { for ( j = 0; nicks[ i ][ j ]!= '\0'; j++ ) putchar( nicks[ i ][ j ] ); putchar( '\n' ); }
53 22. What gets printed by the following? char *nicks[ ] = { "Crash Override", "Acid Burn", "Zero Cool", }; int i, j; int n = sizeof nicks / sizeof nicks[0]; for ( i = 0; i < n; i++ ) { for ( j = 0; nicks[ i ][ j ]!= '\0'; j++ ) putchar( nicks[ i ][ j ] ); putchar( '\n' ); } Crash Override Acid Burn Zero Cool
54 23. What gets printed by the following? char *nicks[ ] = { "Crash Override", "Acid Burn", "Zero Cool", }; int i, j; int n = sizeof nicks / sizeof nicks[0]; int sums[ 10 ]; for ( i = 0; i < n; i++ ) { sums[ i ] = summit( nicks[ i ] ); printf( "Sums [ %d ] = %d.\n", i, sums[i] ); } int total = 0; for ( i = 0; i < n; i++ ) total += sums[ i ]; printf( "Total = %d\n", total );
55 int summit( char *s ) { int i = 0; int count = 0; while ( s[ i ]!= '\0' ) { if ( s[ i ] == 'a' s[ i ] == 'e' s[ i ] == 'i' s[ i ] == 'o' s[ i ] == 'u' s[ i ] == 'y' ) count++; i++; } } return count;
56 Sums [ 0 ] = 4. Sums [ 1 ] = 2. Sums [ 2 ] = 4. Total = 10
57 Caesar Cipher Caesar Cipher is one of the most basic forms of an encryption algorithm. In this type of encryption, each letter in the message is replaced with a letter corresponding to a certain number of letters up or down in the alphabet.
58 Caesar Cipher For example, we can use the algorithm to convert Temple into Ufnqmf
59 Caesar Cipher For example, we can use the algorithm to convert into Temple Ufnqmf (Which is each letter in sequence have increased by 1 location in the alphabet. ASCII makes it easy!)
60 Caesar Cipher void encrypt( char arr[] ) { int i; } for( i = 0; i < strlen( arr ); i++ ) { arr[i] += ROT; }
61 Caesar Cipher void decrypt( char arr[] ) { int i; } for( i = 0; i < strlen( arr ); i++ ) { arr[i] -= ROT; }
62 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char msg[100]; const int rot = 1; void encrypt( char arr[] ) { int i; for( i = 0; i < strlen( arr ); i++ ) { arr[i] += rot; } } void decrypt( char arr[] ) { int i; for( i = 0; i < strlen( arr ); i++ ) { arr[i] -= rot; } } } printf( "Enter your message: " ); fgets( msg, 100, stdin ); printf("\nencrypted Version\n"); encrypt(msg); printf("%s\n",msg); printf("\ndecrypted Version\n"); decrypt(msg); printf("%s",msg); puts(""); return EXIT_SUCCESS;
63 %./a.out Enter your message: Temple Encrypted Version Ufnqmf Decrypted Version Temple %./a.out Enter your message: Luke, I am your father! Encrypted Version Mvlf-!J!bn!zpvs!gbuifs" Decrypted Version Luke, I am your father! %
64 Moving On from Strings
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
More informationFloating-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
More information20 Dynamic allocation of memory: malloc and calloc
20 Dynamic allocation of memory: malloc and calloc As noted in the last lecture, several new functions will be used in this section. strlen (string.h), the length of a string. fgets(buffer, max length,
More informationProgramming refresher and intro to C programming
Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2
More informationProgramming in C++: Assignment Week 1
Programming in C++: Assignment Week 1 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com February 24,
More informationC 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,
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationCS113: 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
More informationString constants. /* Demo: string constant */ #include <stdio.h> int main() {
Strings 1 String constants 2 /* Demo: string constant */ #include s1.c int main() { printf("hi\n"); } String constants are in double quotes A backslash \ is used to include 'special' characters,
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationtoday cs3157-fall2002-sklar-lect05 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 logical
More informationChapter 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
More informationComputer Programming: Skills & Concepts (CP) Strings
CP 14 slide 1 Tuesday 31 October 2017 Computer Programming: Skills & Concepts (CP) Strings Ajitha Rajan Tuesday 31 October 2017 Last lecture Input handling char CP 14 slide 2 Tuesday 31 October 2017 Today
More informationWhy arrays? To group distinct variables of the same type under a single name.
Lesson #7 Arrays Why arrays? To group distinct variables of the same type under a single name. Suppose you need 100 temperatures from 100 different weather stations: A simple (but time consuming) solution
More informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationWriting 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()
More informationCSE 220: Systems Programming
CSE 220: Systems Programming Pointers and Data Representation Ethan Blanton Department of Computer Science and Engineering University at Buffalo More on void Pointers Void pointers are powerful for raw
More informationSOFTWARE Ph.D. Qualifying Exam Fall 2017
(i) (4 pts.) SOFTWARE Ph.D. Qualifying Exam Fall 2017 Consider the following C program. #include #define START 2 #define LIMIT 60 #define STEP 7 #define SIZE 3 int main(void) { int i = START,
More informationCharacters, Character Strings, and string-manipulation functions in C
Characters, Character Strings, and string-manipulation functions in C see Kernighan & Ritchie Section 1.9, Appendix B3 Characters Printable characters (and some non-printable ones) are represented as 8-bit
More informationLibrary Functions. General Questions
1 Library Functions General Questions 1. What will the function rewind() do? A. Reposition the file pointer to a character reverse. B. Reposition the file pointer stream to end of file. C. Reposition the
More informationPointers, Arrays, and Strings. CS449 Spring 2016
Pointers, Arrays, and Strings CS449 Spring 2016 Pointers Pointers are important. Pointers are fun! Pointers Every variable in your program has a memory location. This location can be accessed using & operator.
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationStrings. Steven R. Bagley
Strings Steven R. Bagley Recap Programs are a series of statements Defined in functions Functions, loops and conditionals can alter program flow Data stored in variables or arrays Or pointed at by pointers
More informationPersonal SE. Functions, Arrays, Strings & Command Line Arguments
Personal SE Functions, Arrays, Strings & Command Line Arguments Functions in C Syntax like Java methods but w/o public, abstract, etc. As in Java, all arguments (well, most arguments) are passed by value.
More informationMemory, Arrays & Pointers
1 Memory, Arrays & Pointers Memory int main() { char c; int i,j; double x; c i j x 2 Arrays Defines a block of consecutive cells int main() { int i; int a[3]; i a[0] a[1] a[2] Arrays - the [ ] operator
More informationOverview. Concepts this lecture String constants Null-terminated array representation String library <strlib.h> String initializers Arrays of strings
CPE 101 slides based on UW course Lecture 19: Strings Overview Concepts this lecture String constants ull-terminated array representation String library String initializers Arrays of strings
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationadvanced 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
More informationch = 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
More informationmith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationChapter 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
More informationB.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
More informationMidterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.
Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem
More informationHigh Performance Programming Programming in C part 1
High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationCharacters 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,
More informationChapter 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
More information1 SAT-DANCE-HEULE INTRO 1
1 SAT-DANCE-HEULE INTRO 1 May 19, 2018 at 02:31 1. Intro. Given an exact cover problem, presented on stdin in the format used by DANCE, we generate clauses for an equivalent satisfiability problem in the
More informationReading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14
Reading Assignment Strings char identifier [ size ] ; char * identifier ; K.N. King Chapter 13 K.N. King Sections 23.4, 23.5 Supplementary reading Harbison & Steele Chapter 12, 13, 14 Strings are ultimately
More informationarrays and strings week 3 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 22 imperative programming review
of char imperative week 3 and Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 22 : miscellaneous of char several library functions are have put or get in their name
More informationApproximately 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
More informationCSci 4061 Introduction to Operating Systems. Input/Output: High-level
CSci 4061 Introduction to Operating Systems Input/Output: High-level I/O Topics First, cover high-level I/O Next, talk about low-level device I/O I/O not part of the C language! High-level I/O Hide device
More informationC Characters and Strings
CS 2060 Character handling The C Standard Library provides many functions for testing characters in ctype.h. int isdigit(int c); // is c a digit (0-9)? int isalpha(int c); // is c a letter? int isalnum(int
More informationLAB 6 (2017 June 22/27) Array of pointers. Dynamic memory allocation.
LAB 6 (2017 June 22/27) Array of pointers. Dynamic memory allocation. Due: June 30 (Fri) 11:59 pm Part I Array of pointers vs. 2D arrays. Command line arguments. 1. Problem A Motivation In class lots people
More informationC strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C
C strings (Reek, Ch. 9) 1 Review of strings Sequence of zero or more characters, terminated by NUL (literally, the integer value 0) NUL terminates a string, but isn t part of it important for strlen()
More informationCS16 Exam #1 7/17/ Minutes 100 Points total
CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding
More informationExercise 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
More informationLecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1
Lecture 10 Arrays (2) and Strings UniMAP SEM II - 11/12 DKT121 1 Outline 8.1 Passing Arrays to Function 8.2 Displaying Array in a Function 8.3 How Arrays are passed in a function call 8.4 Introduction
More informationMain 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
More informationStandard C Library Functions
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationComputer 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
More informationUnited States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017
United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 07 - Strings Stephen Scott (Adapted from Christopher M. Bourke) 1 / 51 Fall 2009 Chapter 9 9.1 String 9.2 Functions: Assignment
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 9: Functions I Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture Introduce the switch and goto statements Introduce the arrays in C
More informationArrays Arrays and pointers Loops and performance Array comparison Strings. John Edgar 2
CMPT 125 Arrays Arrays and pointers Loops and performance Array comparison Strings John Edgar 2 Python a sequence of data access elements with [index] index from [0] to [len-1] dynamic length heterogeneous
More informationCS240: Programming in C
CS240: Programming in C Lecture 13 si 14: Unix interface for working with files. Cristina Nita-Rotaru Lecture 13/Fall 2013 1 Working with Files (I/O) File system: specifies how the information is organized
More informationCS201- 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
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 16 January Takako Nemoto (JAIST) 16 January 1 / 15 Strings and pointers #include //11-1.c char str[] = "ABC"; char *ptr = "123"; printf("str = \"%s\"\n",
More informationPresented By : Gaurav Juneja
Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written
More informationC: 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
More informationmith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Hours! D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationBasic and Practice in Programming Lab7
Basic and Practice in Programming Lab7 Variable and Its Address (1/2) What is the variable? Abstracted representation of allocated memory Having address & value Memory address 10 0x00000010 a int a = 10;
More informationCOMP1917: 09 Arrays and Strings
COMP1917: 09 Arrays and Strings Sim Mautner s.mautner@unsw.edu.au August 15, 2016 Sim Mautner (UNSW) COMP1917: 09 Arrays and Strings August 15, 2016 1 / 14 Arrays int sum(int n1, int n2); int sum(int n1,
More informationC Pointers. CS 2060 Week 6. Prof. Jonathan Ventura
CS 2060 Week 6 1 Pointer Variables 2 Pass-by-reference 3 const pointers 4 Pointer arithmetic 5 sizeof 6 Arrays of pointers 7 Next Time Pointers The pointer is one of C s most powerful and important features.
More informationECE551 Midterm Version 1
Name: ECE551 Midterm Version 1 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual
More informationThe C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language Part 2 (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Input/Output Structures and Arrays 2 Basic I/O character-based putchar (c) output getchar
More informationFundamentals 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
More informationFundamentals of Programming Session 8
Fundamentals of Programming Session 8 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationCommunication. Serial port programming
Applied mechatronics Communication. Serial port programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2017 Outline 1 Introduction 2 Terminal I/O programming
More informationThe C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and
The C Programming Language Part 4 (with material from Dr. Bin Ren, William & Mary Computer Science, and www.cpp.com) 1 Overview Basic Concepts of Pointers Pointers and Arrays Pointers and Strings Dynamic
More informationSlide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng
Slide Set 3 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationA brief introduction to C programming for Java programmers
A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationCOP 3223 Final Review
COP 3223 Final Review Jennifer Brown December 2, 2018 1 Introduction 1.1 Variables I. How can we store data in a program? A. Which of these are valid names for variables? i. 9length ii. hello iii. IamASuperCoolName
More informationFile Access. FILE * fopen(const char *name, const char * mode);
File Access, K&R 7.5 Dealing with named files is surprisingly similar to dealing with stdin and stdout. Start by declaring a "file pointer": FILE *fp; /* See Appendix B1.1, pg. 242 */ header
More informationC Basics And Concepts Input And Output
C Basics And Concepts Input And Output Report Working group scientific computing Department of informatics Faculty of mathematics, informatics and natural sciences University of Hamburg Written by: Marcus
More informationC Programming Language Review and Dissection III
C Programming Language Review and Dissection III Lecture 5 Embedded Systems 5-1 Today Pointers Strings Formatted Text Output Reading Assignment: Patt & Patel Pointers and Arrays Chapter 16 in 2 nd edition
More informationPLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST 2011 EXAMINATIONS CSC 209H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: one two-sided 8.5x11
More informationCS 261 Data Structures. Introduction to C Programming
CS 261 Data Structures Introduction to C Programming Why C? C is a lower level, imperative language C makes it easier to focus on important concepts for this class, including memory allocation execution
More informationCS 107 Lecture 5: Arrays. and Pointers in C. Monday, January 22, Stanford University. Computer Science Department
CS 107 Address Value Lecture 5: Arrays 8 and Pointers in C 0x128 3 0x120 Monday, January 22, 2018 9 0x118 Computer Systems Winter 2018-4 Stanford University 0x110 Computer Science Department 2 Reading:
More informationFundamental 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
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationCSCE150A. Introduction. Basics. String Library. Substrings. Line Scanning. Sorting. Command Line Arguments. Misc CSCE150A. Introduction.
Chapter 9 Scanning Computer Science & Engineering 150A Problem Solving Using Computers Lecture 07 - Strings Stephen Scott (Adapted from Christopher M. Bourke) Scanning 9.1 String 9.2 Functions: Assignment
More informationStudent Number: Computer Science 211b Final Examination. 28 April hours
Computer Science 211b Final Examination 28 April 2006 3 hours Student Number: Surname: Given name: Instructions/Notes: The examination has 40 questions on 15 pages, and a total of 150 marks. Put all answers
More informationBİL200 TUTORIAL-EXERCISES Objective:
Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that
More informationComputer Science & Engineering 150A Problem Solving Using Computers. Chapter 9. Strings. Notes. Notes. Notes. Lecture 07 - Strings
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 07 - Strings Scanning Stephen Scott (Adapted from Christopher M. Bourke) 1 / 51 Fall 2009 cbourke@cse.unl.edu Chapter 9 Scanning
More informationOther C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib.
1 The previous lecture Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations Pointer basics 1 Common library functions [Appendix of K+R]
More informationECE551 Midterm Version 2
Name: ECE551 Midterm Version 2 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual
More informationIntroduction 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
More informationECE2049: Homework 1. Due: Thursday, 25 May 2017 by 7pm
Due: Thursday, 25 May 2017 by 7pm Submission notes: For full credit, please show your work and denote your answers with a circle or a box. Always write and draw your diagrams neatly! We cannot be expected
More informationThe output: The address of i is 0xbf85416c. The address of main is 0x80483e4. arrays.c. 1 #include <stdio.h> 3 int main(int argc, char **argv) 4 {
Memory A bit is a binary digit, either 0 or 1. A byte is eight bits, and can thus represent 256 unique values, such as 00000000 and 10010110. Computer scientists often think in terms of hexadecimal, rather
More informationmith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut
mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu Outline A Few Words about HW 8 Finish the Input Port Lab! Revisiting Homework
More informationC++ For Science and Engineering Lecture 15
C++ For Science and Engineering Lecture 15 John Chrispell Tulane University Wednesday September 29, 2010 Function Review Recall the basics you already know about functions. Provide a function definition.
More informationC Language Part 3. Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 3 Pointers (revisited) int i = 4, j = 6, *p = &i, *q = &j, *r; if (p == &i)...; if (p == (& i))...;... = **&p;... = *(*(& p));... = 9 * *p / *q + 8;... = (((9*(*p)))/(*q)) + 8; *(r = &i)
More informationM.CS201 Programming language
Power Engineering School M.CS201 Programming language Lecture 9 Lecturer: Prof. Dr. T.Uranchimeg Agenda The char Data Type Using Character Variables Printing extended ASCII characters Arrays of Characters
More information