37_pdfsam_cs2022 - String example #include <stdio.h>...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
String example #include <stdio.h> // change uppercase letters in str to lowercase void to_lowercase ( char *str) { for( ; *str ; str++) *str-’A’+'a' : *str; } int main() { char message[] = “Five Hundred Twenty-Five Thousand”; printf(“%s\n”, message); to_lowercase(message); printf(“%s\n”, message); return 0; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Built-in string functions string.h has functions for manipulating null- terminated strings, e.g. strlen(char *s) : returns length of s strlen(char *s1, char *s2) : appends s2 to s1 s1 must point to enough space to hold the result! strcpy(char *s1, char *s2) : copies s2 into s1 Again, s1 must point to enough space returns 0 if the two strings are equal returns a positive integer if s1 lexicographically greater than s2 returns a negative integer if s1 lexicographically less than s2
Background image of page 2
String headaches Remember that you are responsible for
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/10/2010 for the course CS 2022 at Cornell University (Engineering School).

Page1 / 6

37_pdfsam_cs2022 - String example #include &lt;stdio.h&gt;...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online