Procedural Programming & Fundamentals of Programming

Size: px
Start display at page:

Download "Procedural Programming & Fundamentals of Programming"

Transcription

1 Procedural Programming & Fundamentals of Programming Exercise 3 (SS 2018) What will I learn in the 4. exercise Pointer (and a little bit about memory allocation) Structure Strings and String functions in strings.h Exercise(s) FoP & PP 2 1

2 Task 8 Write a program which compares the length of 2 vectors of the form V1=(X1,X2,X3), V2=(Y1,Y2,Y3). The program should print out the result in the form: V1 > V2 or V1 < V2 or V1 = V2 The vectors should be read in into 2 arrays. The comparison of the vectors length should be realized by the function: int compveclen(int v1[], int v2[]) Hint: The length of a vector is calculated by V = x 2 + y 2 +z 2 FoP & PP 3 Why pointer? Allow us to get access to dedicated memory addresses. Advantages: allows low level programming (Example: access to registers of a micro controller) handling of unknown amount of data possibilty to return via a function more than one result (pass by reference) creation of complex data structures (binary trees or linked lists, etc.) FoP & PP 4 2

3 Pointer operators There are two pointer operators in C, known as: & The address of operator. Returns the memory address of a variable. * The dereferencing operator. Allows to access the content of that memory cell where the pointer refers to. (Hint: The asteriks * is also used for the declaration of a pointer) FoP & PP 5 Pointer declaration A pointer to an address where the value of a data type is or can be stored is defined by: <data type> * <identifier>; Examples: int *ip; //declaration of a pointer to addresses //where integer values are stored. char *cp; //declaration of a pointer to addresses //where character values are stored. FoP & PP 6 3

4 Memory management When we declare a normal variable like char or int or double the compiler takes care that the program will reserve the appropiate memory for that variable. Reserved memory depends on data type and machine architecture. When we declare a pointer variable the compiler reserves sufficient memory for storing an address. FoP & PP 7 Address assignment When we define a pointer variable without initialization, where does the pointer refer to? Answer: It points to an arbitrary address. In order to assign a valid address to the pointer we can do the following: int i; // define an integer variable i int *ip // define an integer pointer ip ip = &i;// ip refers now to the address // where the value of i is stored. => Take care that your pointer are working with the right addresses. FoP & PP 8 4

5 Pointer: simple example int main() int i; // no init => random values; int *ip; // no init => points to anywhere printf( value of i=%d, address of i=%p,i,&i); printf( value of ip=%d, address of ip=%p,ip, &ip); i = 5; //assign 5 to i ip = &i; //assignment of the address of i to ip printf( value of i=%d, address of i=%p,i,&i); printf( value of ip=%d, address of ip=%p,ip, &ip); printf( value of memorycell refered by ip:%d,*ip); FoP & PP 9 Memory values before and after init (assignments) Address (32 bit) : FFFF0000 FFFF0001 FFFF0002 FFFF0003 FFFF0004 FFFF0006 FFFF0007 FFFF0008 FFFF0009 : FFFFFFFF Value (8bit) random VALUE random VALUE 4 bytes reserved for variable i at address FFFF bytes for the pointer pi at address FFFF0004 i = 5; => pi = &i; => Access to the value 5 via the pointer pi is possible by: *pi Address (32 bit) : FFFF0000 FFFF0001 FFFF0002 FFFF0003 FFFF0004 FFFF0006 FFFF0007 FFFF0008 FFFF0009 : FFFFFFFF Value (8bit) 5 FFFF0000 FoP & PP 10 5

6 Pointer and arrays (1) Pointers and arrays have a close relationship and can be treated in the same way. If you declare an array like int a[10] then a itself can be seen as pointer to the address where the first element is stored. Example: int iarr[10], *ip; ip = iarr; // ip and iarr refer same address // access to the first element possible by iarr[0] = 5; or *ip = 5; or *iarr = 5; FoP & PP 11 Pointer and arrays (2) How can we access the second (and following) element(s) by the pointer? Answer: Increment the pointer. That means, assuming we did ip = iarr then: ip points to memory cell of iarr[0] (ip+1) points to memory cell of iarr[1] (ip+2) points to memory cell of iarr[2] => *ip=5 //equal to iarr[0]=5 => *(ip+1)=6 //equal to iarr[1]=6 => *(ip+2)=7 //equal to iarr[2]=7 FoP & PP 12 6

7 Pointer and arrays (3) Address (32 bit) : FFFF0000 FFFF0001 FFFF0002 FFFF0003 FFFF0004 FFFF0006 FFFF0007 FFFF0008 FFFF0009 FFFF000A : Value (8bit) (Iarr[0]) 5 (Iarr[1]) 6 (Iarr[2]) 7 Initialization pi = iarr; pi points to *(pi) accesses (pi+1) points to *(pi+1) accesses (pi+2) points to *(pi+2) accesses Address (32 bit) : FFFF0000 FFFF0001 FFFF0002 FFFF0003 FFFF0004 FFFF0006 FFFF0007 FFFF0008 FFFF0009 FFFF000A : Value (8bit) (Iarr[0]) 5 (Iarr[1]) 6 (Iarr[2]) 7 FoP & PP 13 Pointer and arrays (4) Keep in mind: Declaring an array means that the right memory space is reserved for you. Declaring a pointer reserves only the space to store a memory address. FoP & PP 14 7

8 Pointer arithmetic It is allowed to do arithmetic operations with a pointer like increment, add an integer value,etc. The new calculated address where the pointer refers to depends on the data type used for the pointers definition. Example: int pointer ip (int *ip), int uses 4 byte memory space, assumption: ip refers to addr FFFF0000 doing increment ip++ => pointer ip refers then to FFFF0004 FoP & PP 15 Pass by reference If we pass arguments to a function we can also use pointers as arguments. Called pass by reference. In our function we use the dereference * parameter in order to access the value which is stored under the address where the argument (pointer) refers to. => Allows us to return multiple function results via the arguments. FoP & PP 16 8

9 Task 9 A program should add two vectors x,y (length 3). This should be done by a function addvec with 3 arguments: - v1: reference to the first vector - v2: reference to the second vector - n: number of elements in the vector The result (sum of the vectors) should be stored in the array where v1 refers to. FoP & PP 17 Request for memory during runtime What can we do if our program must be able deal with a variable amount of data? We request new memory during runtime! Can be done by the function: void *malloc(size_t size); Function reserves a continguos memory area of size bytes and returns a void pointer to the new memory. Memory can be released by function free FoP & PP 18 9

10 Sizeof Used memory space of a variable depends on data type and machine architecture. How can I determine the space of memory which is used for a special data type? Answer: sizeof operator. The sizeof (data type) returns the number of bytes used for that data type. Example : sizeof (char)=> 1 sizeof (int) => 2 or 4 (depends on architecture) FoP & PP 19 Request for memory to store n characters int main() unsigned int i,n; // no init => random value; char *cp; // no init => points to anywhere printf( How many character values: ); scanf( %d,&n); cp = (char*)malloc(sizeof(char)*n); for(i=0;i < n; i++) printf( \nnext char: ); scanf( %c,(cp+i)) //could be also cp[i] printf("\nchar[0]:%c, char[%d]:%c",*cp,n-1,*(cp+n-1)); FoP & PP 20 10

11 Structures A collection of related variables of the same and or/different data types. Declaration example for a point which is specified by x,y,z coordinates and a color struct point int x,y,z; //coordinates unsigned char color; //256 colors possible ; FoP & PP 21 Definition of new data types C allows the definition of new data types by use of typedef. Useful because new data types can be treated like normal data types. Example: typedef struct int x,y,z; unsigned char R,G,B; point; //new data type point is defined //declare variable apoint and a pointer pp point apoint, *pp; point.x = 5; point.y = 6; point.z = 7; FoP & PP 22 11

12 Task 10 Write a program which is able to handle exam results by use of an array of structures. The data for an exam are: - Mark: Exam identifier : simple number 6 digits - Matriculation-No.: simple number 6 digits Requirements: The program asks for the number of exams Declare a structure exam which contains (Mark, Exam-ID, Matr) The program reserves memory via malloc in dependency of the number of exams The program aks for all exams all data (Mark, Exam-ID, Matr) The program determines the number of passed (Mark <= 4.0) exams. FoP & PP 23 Task 11 A program should be created which is able to sort points regarding its x-coordinates. A point is defined by its x,y,z coordinates and its color (R,G,B values). - The user is asked how many points he wants to enter. - For every point the coordinates must be entered - The color values of a new point are initialized - The sorted list of points is printed FoP & PP 24 12

13 Strings C does not have an own String datatype Implemented as array of characters A constant string is enclosed in double quotes like Hello The end of the string is determined by the NULL character \0. Must be considered as an additional char (array length). VERY IMPORTANT because it is required for all string functions FoP & PP 25 String Example char mystr[] = Hello //requires 6 chars is equal to char mystr[6] = Hello ; is equal to char mystr[6] = H, e, l, l, o, \0 ; NULL character determines end of string FoP & PP 26 13

14 Strings and Pointer Because pointer and arrays have a close relation, pointer are often used together with strings. Example: char str[]= Hello students ; char *strp; strp = str; //strp refers now to str //print out Hello students printf( %s,strp); //print out llo students ; printf( %s,strp+2); //print out s, s printf %c, %c, strp[6],str[6]); FoP & PP 27 String operations Typical string operations are: Get the length of a string Copy a string into another Concatenate two strings Find a char or a substring within a string Compare two strings Functions doing all these are available in string.h FoP & PP 28 14

15 strlen size_t *strlen(const char* str) string length returns the length of the string. The terminating null character \0 is not counted. size_t is typically defined as unsigned int. Example: char source[] = Hello ; int i; i = strlen(source); //i = 5 FoP & PP 29 strcpy char *strcpy(char * dest, const char* src) string copy copies the string pointed to by src into the array pointed to by dest. The array pointed by dest must be large enough to contain the same C string as src (including the terminating null character ( \0 ). Example: char source[] = World ; char dest[6] ; strcpy(dest, source); // dest is now World // altogether 6 characters including \0 FoP & PP 30 15

16 strcat char *strcat(char * dest, const char* src) string concatenate appends a copy of source (src) to the destination string (dest). The array pointed by dest must be large enough to contain both the orginal source string and the destination string. Example: char source[]= Students ; char dest[15] = Hello ; strcat(dest, source); //dest is now Hello Students //(15 chars including \0 ) FoP & PP 31 strchr, strstr char *strchr(const char str*, int c) string character returns a pointer to the first appearance of c in str or a null pointer if c does not appear in str char *strstr(const char *s1, const char *s2) string in string returns a pointer to the first occurrence of s2 in s1, or a null pointer if s2 is not part of s1. FoP & PP 32 16

17 strcmp int strcmp(const char *s1, const char *s2) string compare compare the string s1 with s2. A zero value indicates that both strings are equal. A value greater than zero indicates that the first character that does not match has a greater value in s1 than in s2. For example: aab is larger than aaa A value less than zero indicates the opposite. FoP & PP 33 Task 12 A program should allow the user to enter two strings s1 and s2. This two strings should then combined together to a new string s12. The array for the new string should have exactly the right length. Then the user can enter a third string s3. It should be checked if the string s3 is part of the new string s12. FoP & PP 34 17

18 Programming style Use spaces in source code (easier to read) Use BlockCodes Descriptive names for variables and use CamelCase. Example: (int nrofadders) Initialize your variables Use constant or defines for fixed values Use comments Avoid long lines and complex statements FoP & PP 35 18

19 #include <stdio.h> //Task 8 #include <stdlib.h> #define ARR_MAX 3 int compveclen(int v1[], int v2[], int n) long v1len = 0, v2len= 0; for (--n; n >=0; n-- ) v1len = (long)v1[n] * (long)v1[n] + v1len; v2len = (long)v2[n] * (long)v2[n] + v2len; if (v1len == v2len) return 0; if (v1len > v2len) return 1; return 2; //v1len < v2len int main() int v1arr[arr_max],v2arr[arr_max], i=0; char coch[] = '=','>','<' ; do printf("\nplease, input x%d:",i+1); scanf("%d",&v1arr[i]); fflush(stdin); printf("please, input y%d:",i+1); scanf("%d",&v2arr[i]); fflush(stdin); while(++i < ARR_MAX); i = compveclen(v1arr, v2arr, ARR_MAX); printf("\n V1 %c V2 ",coch[i]); return EXIT_SUCCESS; 15

20 //Task 9 #include <stdio.h> #include <stdlib.h> #define ARR_MAX 3 void addvec(int *v1, int *v2, int n) while(--n >=0) v1[n] = v1[n] + v2[n]; //*(v1+n) = *(v1+n) + *(v2+n); //*(v1) = *v1 + *v2; v1++; v2++; int main() int v1arr[arr_max],v2arr[arr_max], i=0; do printf("\nplease, input x%d:",i); scanf("%d",&v1arr[i]);fflush(stdin); printf("please, input y%d:",i); scanf("%d",&v2arr[i++]);fflush(stdin); while(i < ARR_MAX); addvec(v1arr, v2arr, ARR_MAX); printf("\nsum of x,y ="); for (i=0; i < ARR_MAX; i++ ) printf("%d, ",v1arr[i]); return EXIT_SUCCESS; 2

21 // Task 10 #include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct float mark; unsigned long examident, matr; exam; int main() unsigned int i,n, cp=0; exam *pexam; printf("how many exams :"); scanf("%d",&n); pexam = (exam*)calloc(n, sizeof(exam)); for(i=0;i < n; i++) printf("\nexam(%d) mark:",i+1); fflush(stdin); scanf("%f",&pexam[i].mark); printf("exam(%d) examident:",i+1); flush(stdin); scanf("%d",&pexam[i].examident); printf("exam(%d) Matriculation:",i+1); fflush(stdin); scanf("%d",&pexam[i].matr); if (pexam[i].mark <= 4.0) cp++; printf("\nnumber of passed exams:%d",cp); free(pexam); 4

22 // Task 11 typedef struct int x,y,z; unsigned char R,G,B; point; void sortp(point *parr, int n) int i,j; point temp; for (i=0;i < n-1; i++) for (j=i+1; j < n; j++) if(parr[i].x > parr[j].x) temp = parr[i]; parr[i] = parr[j]; parr[j] = temp; int main() unsigned int i,n; point *pp; printf("how many point values:"); scanf("%d",&n); pp = (point*)calloc(n, sizeof(point)); for(i=0;i < n; i++) printf("point x,y,z:"); fflush(stdin); scanf("%d,%d,%d",&pp[i].x,&pp[i].y,&pp[i].z ); sortp(pp,n); for (i=0; i< n; i++) printf("\npt[%d]:%d,%d,%d",i,pp[i].x,pp[i].y,pp[i].z); free(pp); 6

23 // Task 12 #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <string.h> int main() char buffer[1024], *str[3], *str12; unsigned int i,strl; for(i=0; i < 3; i++) printf("\ninput s%d:",i+1); fflush(stdin); scanf("%s",buffer); strl = strlen(buffer)+1; str[i] = (char*)malloc(sizeof(char) * strl); strcpy(str[i], buffer); strl = strlen(str[0]) + strlen(str[1])+1; str12= (char*)(malloc(strl * sizeof(char))); strcpy(str12,str[0]); strcat(str12,str[1]); printf("\n\nnew s12 is:%s",str12); if (strstr(str12,str[2])!=null) printf("\ns3 is part of s12"); else printf("\ns3 is not part of s12"); 8

Procedural Programming

Procedural Programming Exercise 5 (SS 2016) 28.06.2016 What will I learn in the 5. exercise Strings (and a little bit about pointer) String functions in strings.h Files Exercise(s) 1 Home exercise 4 (3 points) Write a program

More information

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

CSC209H Lecture 4. Dan Zingaro. January 28, 2015 CSC209H Lecture 4 Dan Zingaro January 28, 2015 Strings (King Ch 13) String literals are enclosed in double quotes A string literal of n characters is represented as a n+1-character char array C adds a

More information

Programming in C. Session 7. Seema Sirpal Delhi University Computer Centre

Programming in C. Session 7. Seema Sirpal Delhi University Computer Centre Programming in C Session 7 Seema Sirpal Delhi University Computer Centre Relationship between Pointers & Arrays In some cases, a pointer can be used as a convenient way to access or manipulate the data

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 9 Principles of C and Memory Management Dr Lei Shi Last Lecture Today Pointer to Array Pointer Arithmetic Pointer with Functions struct Storage classes typedef union String struct struct

More information

Pointers, Arrays, and Strings. CS449 Spring 2016

Pointers, 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 information

ECE551 Midterm Version 1

ECE551 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 information

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER: Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 2 Wednesday, March 18, 2015 ANSWERS Duration of examination: 75 minutes STUDENT

More information

Computer Programming: Skills & Concepts (CP) Strings

Computer 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 information

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size] (November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I

More information

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University SYSC 2006 C Winter 2012 String Processing in C D.L. Bailey, Systems and Computer Engineering, Carleton University References Hanly & Koffman, Chapter 9 Some examples adapted from code in The C Programming

More information

Memory, Arrays & Pointers

Memory, 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 information

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Pointer Arithmetic and Element

More information

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

Intermediate Programming, Spring 2017*

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 information

ECE551 Midterm Version 2

ECE551 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 information

CSCI 6610: Intermediate Programming / C Chapter 12 Strings

CSCI 6610: Intermediate Programming / C Chapter 12 Strings ... 1/26 CSCI 6610: Intermediate Programming / C Chapter 12 Alice E. Fischer February 10, 2016 ... 2/26 Outline The C String Library String Processing in C Compare and Search in C C++ String Functions

More information

ECE 551D Spring 2018 Midterm Exam

ECE 551D Spring 2018 Midterm Exam Name: ECE 551D Spring 2018 Midterm Exam NetID: There are 6 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 information

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and

More information

Introduction to string

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

More information

EM108 Software Development for Engineers

EM108 Software Development for Engineers EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and

More information

CS1100 Introduction to Programming

CS1100 Introduction to Programming CS1100 Introduction to Programming Sorting Strings and Pointers Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Lexicographic (Dictionary) Ordering Badri

More information

C Programming Language Review and Dissection III

C 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 information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

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. 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 information

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER: Page 1 of 7 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2014 Midterm Examination # 2 Wednesday, March 19, 2014 ANSWERS Duration of examination: 75 minutes STUDENT

More information

Lecture 05 Pointers ctd..

Lecture 05 Pointers ctd.. Lecture 05 Pointers ctd.. Note: some notes here are the same as ones in lecture 04 1 Introduction A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct

More information

Procedural Programming & Fundamentals of Programming

Procedural Programming & Fundamentals of Programming & Fundamentals of Programming Exercise 4 (SS 2018) 12.06.2018 What will I learn in the 5. exercise Files Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Files A file can be seen as

More information

ECE 551D Spring 2018 Midterm Exam

ECE 551D Spring 2018 Midterm Exam Name: SOLUTIONS ECE 551D Spring 2018 Midterm Exam NetID: There are 6 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam

More information

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

Reading 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 information

Procedural Programming

Procedural Programming Exercise 3 (SS 2017) 20.05.2017 What will I learn in the 3. Exercise Functions Arrays Exercise(s) 1 Home exercise 2 (3 points) Write a program which allows the calculation of the mean of given integer

More information

ARRAYS(II Unit Part II)

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

More information

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. Name: ECE551 Midterm 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 work. You

More information

CSC 2400: Computer Systems. Arrays and Strings in C

CSC 2400: Computer Systems. Arrays and Strings in C CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays: C vs.

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

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

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

More information

8. Characters, Strings and Files

8. 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 information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Outline Review pointers New: Strings New: Variable Scope (global vs. local variables)

More information

ECE551 Midterm Version 1

ECE551 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 information

CSC 2400: Computer Systems. Arrays and Strings in C

CSC 2400: Computer Systems. Arrays and Strings in C CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays in C

More information

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs

More information

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

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

More information

Grade Distribution. Exam 1 Exam 2. Exams 1 & 2. # of Students. Total: 17. Total: 17. Total: 17

Grade Distribution. Exam 1 Exam 2. Exams 1 & 2. # of Students. Total: 17. Total: 17. Total: 17 Grade Distribution Exam 1 Exam 2 Score # of Students Score # of Students 16 4 14 6 12 4 10 2 8 1 Total: 17 Exams 1 & 2 14 2 12 4 10 5 8 5 4 1 Total: 17 Score # of Students 28 2 26 5 24 1 22 4 20 3 18 2

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables 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 information

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub 2Computer Science BS Degree -Imperative Programming

More information

Character Strings. String-copy Example

Character Strings. String-copy Example Character Strings No operations for string as a unit A string is just an array of char terminated by the null character \0 The null character makes it easy for programs to detect the end char s[] = "0123456789";

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Chapter 8 Character Arrays and Strings

Chapter 8 Character Arrays and Strings Chapter 8 Character Arrays and Strings INTRODUCTION A string is a sequence of characters that is treated as a single data item. String constant: String constant example. \ String constant example.\ \ includes

More information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Seven: Strings and Files Name: First Name: Tutor: Matriculation-Number: Group-Number:

More information

CSCE150A. Introduction. Basics. String Library. Substrings. Line Scanning. Sorting. Command Line Arguments. Misc CSCE150A. Introduction.

CSCE150A. 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 information

mith 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 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 information

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 9. Strings. Notes. Notes. Notes. Lecture 07 - Strings

Computer 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 information

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook Chapter 5 Section 5.4 The Common String Library Functions CS 50 Hathairat Rattanasook Library Functions We already discussed the library function fgets() Library functions are available: to find the length

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer 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 information

PDS Class Test 2. Room Sections No of students

PDS Class Test 2. Room Sections No of students PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Spring 2018 COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Computers Programming Course 10. Iulian Năstac

Computers Programming Course 10. Iulian Năstac Computers Programming Course 10 Iulian Năstac Recap from previous course 5. Values returned by a function A return statement causes execution to leave the current subroutine and resume at the point in

More information

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7 Strings and Clases BIL104E: Introduction to Scientific and Engineering Computing Lecture 7 Manipulating Strings Scope and Storage Classes in C Strings Declaring a string The length of a string Copying

More information

Arrays and Strings. CS449 Fall 2017

Arrays and Strings. CS449 Fall 2017 Arrays and Strings CS449 Fall 2017 Arrays Data type for a sequence of variables of the given element type in consecubve memory Element type can be any data type. E.g. char A[10]; // sequence of chars int

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

CSC209H1S Day Midterm Solutions Winter 2010

CSC209H1S Day Midterm Solutions Winter 2010 Duration: Aids Allowed: 50 minutes 1-8.5x11 sheet Student Number: Last Name: SOLUTION First Name: Instructor: Karen Reid Do not turn this page until you have received the signal to start. (In the meantime,

More information

TELE402. Internetworking. TELE402 Lecture 1 Protocol Layering 1

TELE402. Internetworking. TELE402 Lecture 1 Protocol Layering 1 TELE402 Internetworking TELE402 Lecture 1 Protocol Layering 1 People Lecturer Dr. Zhiyi Huang Email: hzy@cs.otago.ac.nz Phone: 479-5680 Office: 1.26 Owheo Building Teaching Assistant Kai-Cheung Leung Email:

More information

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses

More information

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY Strings Arrays of characters Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY 1 Basics Strings A string is a sequence of characters treated as a group We have already

More information

C Programming Multiple. Choice

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

More information

Create a Program in C (Last Class)

Create a Program in C (Last Class) Create a Program in C (Last Class) Input: three floating point numbers Output: the average of those three numbers Use: scanf to get the input printf to show the result a function to calculate the average

More information

Iosif Ignat, Marius Joldoș Laboratory Guide 9. Character strings CHARACTER STRINGS

Iosif Ignat, Marius Joldoș Laboratory Guide 9. Character strings CHARACTER STRINGS CHARACTER STRINGS 1. Overview The learning objective of this lab session is to: Understand the internal representation of character strings Acquire skills in manipulating character strings with standard

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 8 Principles of C and Memory Management Dr Lei Shi Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic, Functions Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic,

More information

Using Character Arrays. What is a String? Using Character Arrays. Using Strings Life is simpler with strings. #include <stdio.

Using Character Arrays. What is a String? Using Character Arrays. Using Strings Life is simpler with strings. #include <stdio. What is a String? A string is actually a character array. You can use it like a regular array of characters. However, it has also some unique features that make string processing easy. Using Character

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers

More information

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings Using Strings The string in C programming language is actually a one-dimensional

More information

High Performance Programming Programming in C part 1

High 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 information

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Lehrstuhl Informatik V bader@in.tum.de March, 4th March, 8th, 2002 Abstract This is where an abstract might go if you want one. There is usually not a lot of room for much here. C/C++ Tutorial

More information

CS 222: Pointers and Manual Memory Management

CS 222: Pointers and Manual Memory Management CS 222: Pointers and Manual Memory Management Chris Kauffman Week 4-1 Logistics Reading Ch 8 (pointers) Review 6-7 as well Exam 1 Back Today Get it in class or during office hours later HW 3 due tonight

More information

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters Using Strings The string in C programming language is actually a one-dimensional

More information

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:

More information

CSE 333 Midterm Exam 2/14/14

CSE 333 Midterm Exam 2/14/14 Name There are 4 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

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

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

More information

Language comparison. C has pointers. Java has references. C++ has pointers and references

Language comparison. C has pointers. Java has references. C++ has pointers and references Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified

More information

CSCI-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 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 information

Arrays, Pointers, and Strings

Arrays, Pointers, and Strings Arrays, Pointers, and Strings Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 ARRAYS 2 Array An array is a set of subscripted variables of the same type int a[10]; char a[20]; Why we need arrays? Making code

More information

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

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

More information

Programming. Pointers, Multi-dimensional Arrays and Memory Management

Programming. Pointers, Multi-dimensional Arrays and Memory Management Programming Pointers, Multi-dimensional Arrays and Memory Management Summary } Computer Memory } Pointers } Declaration, assignment, arithmetic and operators } Casting and printing pointers } Relationship

More information

CS 61c: Great Ideas in Computer Architecture

CS 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 information

BİL200 TUTORIAL-EXERCISES Objective:

Bİ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 information

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

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

More information

Lecture 04 Introduction to pointers

Lecture 04 Introduction to pointers Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable

More information

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21 Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to

More information

C mini reference. 5 Binary numbers 12

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

More information

Dynamic memory. EECS 211 Winter 2019

Dynamic memory. EECS 211 Winter 2019 Dynamic memory EECS 211 Winter 2019 2 Initial code setup $ cd eecs211 $ curl $URL211/lec/06dynamic.tgz tar zx $ cd 06dynamic 3 Oops! I made a mistake. In C, the declaration struct circle read_circle();

More information

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 3, November 20, 2013 ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

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

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

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013 Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

More information

C Characters and Strings

C 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 information

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,

More information