Class Notes (835,600)
Canada (509,275)
CS 137 (16)
Lecture 15

Programming Lecture 15.docx

3 Pages
46 Views
Unlock Document

Department
Computer Science
Course
CS 137
Professor
Andrew Morton
Semester
Fall

Description
Programming Lecture 15 Nov 8, 2012 Char  3-byte chars o Codepoint  xxxx yyyyyy zzzzzz  Up to 16 bits o Becomes  1110 xxxx 10yyyyyy 10zzzzzz o Represents cod16oints  2048-2 -1 (65 535)  4-byte chars o Codepoint  xxx yyyyyy zzzzzz wwwwww  Up to 18 bits o Becomes  1110 xxx 10yyyyyy 10zzzzz 10wwwwww o Represents codepoints  65 536 – 2 – 1 ( 2 097 151)  EX: o 26 085 = 0110/0101 11/10 0101 o UTF-8: 1110 0110 1 Strings  Array of chars terminated by ‘\0’  EXAMPLE o char s[] = “hello”; S: ‘h’ ‘e’ ‘l’ ‘l’ ‘o’ ‘\0’ o char s[] = {‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’}; o char *s = “hello”; Example // count occurrences of char c in string s #include int count (char s[], char c) { int n = 0; for (int i=0;s[i]!=’\0’; i++) if (s[i]==c) n++; return n; } int main () { char *hi = “Hello world”; printf(“%d\n”, count (hi, ‘l’); //prints 3 printf(“%d\n”, count (hi, ‘o’)); //prints 2 } OR int count (char *s, char c) { int n=0; for (; *s
More Less

Related notes for CS 137

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit