Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial #8 Summer 2005. strings #include int main() { char str1[] = {‘h’,’e’,’l’,’l’,’o’}; char str[] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; char p[] = ”hello”;

Similar presentations


Presentation on theme: "Tutorial #8 Summer 2005. strings #include int main() { char str1[] = {‘h’,’e’,’l’,’l’,’o’}; char str[] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; char p[] = ”hello”;"— Presentation transcript:

1 Tutorial #8 Summer 2005

2 strings #include int main() { char str1[] = {‘h’,’e’,’l’,’l’,’o’}; char str[] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; char p[] = ”hello”; printf(“%s\n”, str); return 0; }

3 strings int main() { char  str = ”hello”; char p[] = ”hello”; printf(“%c%c%c%c%c\n”,  str,  (str+1), str[2], str[3], str[4]); return 0; }

4 strings #include int main() { char *p = ”hello”; printf(“%s %s %s %s %s\n”, p, p + 1, p + 2, p + 3, p + 4); return 0; }

5 Pointer and array int main() { char amessage[] = “now is the time”; char *pmessage; pmessage = “now is the time”; }

6 Char functions #include int isdigit(int) int isspace(int) int isupper(int) int islower(int)

7 String functions #include char  strcat(char* s1, const char  s2) char str[11] = “hello”, str2[] = “world”; strcat(str, str2); char  strcpy(char* s1, const char  s2) unsigned strlen(const char  s) int strcmp(const char  s1, const char  s2)

8 strlen int strlen(char *s) { int n; for(n = 0; *s != ‘\0’; s++) n++; return n; }

9 strlen int strlen(char *s) { char *p = s; while (*p != ‘\0’) p++; return p – s; }

10 strcopy void strcopy(char *s, char *t) { int i = 0; while ((s[i] = t[i]) != ‘\0’) i++; }

11 strcopy void strcopy(char *s, char *t) { while ((*s = *t) != ‘\0’) { s++; t++; }

12 strcopy void strcopy(char *s, char *t) { while ((*s++ = *t++) != ‘\0’) ; }

13 strcopy void strcopy(char *s, char *t) { while (*s++ = *t++) ; }

14 strcat char  strcat( char *s1, char *s2) { char *p = s1; while(*p) p++; while(*p++ = *s2++) ; return s1; }

15 strcmp int strcmp(char *s, char *t) { int i; for (i = 0; s[i] == t[i]; i++) if (s[i] == ‘\0’) return 0; return s[i] – t[i]; }

16 Strcmp int strcmp(char *s, char *t) { for ( ; *s == *t; s++, t++) if (*s == ‘\0’) return 0; return *s – *t; }


Download ppt "Tutorial #8 Summer 2005. strings #include int main() { char str1[] = {‘h’,’e’,’l’,’l’,’o’}; char str[] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; char p[] = ”hello”;"

Similar presentations


Ads by Google