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”;

Slides:



Advertisements
Similar presentations
C’ POINTERS Basic&Examples. Q:what’s the output? int array[] = { 45, 67, 89 }; int *array_ptr = array; printf(" first element: %i\n", *(array_ptr++));
Advertisements

 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
Pseudocode A way to make programming easier Start with a verbal description of what the program is supposed to do! Slowly transform it into C, defining.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Lecture 09 Strings, IDEs. METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan Mon July 29, 2002.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Chapter Fourteen Strings Revisited. Strings A string is an array of characters A string is a pointer to a sequence of characters A string is a complete.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
1 Introduction to Computing: Lecture 16 Character Strings Dr. Bekir KARLIK Yasar University Department of Computer Engineering
CS 241 Section Week #2 2/4/10. 2 Topics This Section MP1 overview Part1: Pointer manipulation Part2: Basic dictionary structure implementation Review.
C programming---String. String Literals A string literal is a sequence of characters enclosed within double quotes: “hello world”
C strings (Reek, Ch. 9) 1CS 3090: Safety Critical Programming in C.
Character Arrays strlen("hello, world"); /* string constant */ strlen(array); /* char array[100]; */ strlen(ptr); /* char *ptr; */ char pmessage[] = "now.
C Strings Systems Programming. Systems Programming: Strings 22 StringsStrings  Strings versus Single characters  Pointers versus Arrays  Accessing.
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
C Arrays and Pointers In Java, pointers are easy to deal with –In fact, there is little that can go wrong in Java since pointer access is done for you.
C-Strings Joe Meehean. C-style Strings String literals (e.g., “foo”) in C++ are stored as const char[] C-style strings characters (e.g., ‘f’) are stored.
Computer Science 210 Computer Organization Strings in C.
Introduction to C programming
Data Type string #include // C++ String class string str1, str2; // Default constructor cin >> str1 >> str2; cout
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
BBS514 Structured Programming (Yapısal Programlama)1 Character Processing, Strings and Pointers,
CPT: Strings/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss strings and their relationship.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 13 Strings (Continued)
CS 162 Introduction to Computer Science Chapter 17 C++ String Objects Herbert G. Mayer, PSU (Copied from Prof. Phillip Wong at PSU) Status 11/30/2014.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
Xuan Guo Review for the Final Exam Xuan Guo July 29 8:30AM – 10:30AM Classroom South 300 CSC
String functions+ string I.Mona Alshehri. String Functions: Header file:#include Function: Int strlen(char s[n]) Description Calculates the length of.
Chapter 8: Character and String CMPD144: Programming 1.
1 This chapter covers both string constants (or literals, as they're called in the C standard) and string variables, which can change during the execution.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
CS 1430: Programming in C++ 1. Data Type string #include // C++ String class string str1, str2; // Default constructor cin >> str1 >> str2; cout
13. Strings. String Literals String literals are enclosed in double quotes: "Put a disk in drive A, then press any key to continue\n“ A string literal.
Strings Jarret Raim C Strings Same as arrays of characters. Use pointers. Require static declarations (compile time). No bounds checking. No easy.
COP 3275 – Character Strings and Introduction to Pointers Instructor: Diego Rivera-Gutierrez.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Characters and Strings Functions.
CMSC 104, Version 8/061L25Strings.ppt Strings Topics String Libraries String Operations Sample Program Reading Sections
ENEE150 – 0102 ANDREW GOFFIN Strings. Project 2 Flight Database 4 options:  Print flight  Print airport  Find non-stop flights  Find one-stop flights.
Built-in Functions for NTCAs. strlen char array[10] = “Hello”; int length = strlen(array); cout
Today’s Material Strings Definition Representation Initialization
1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments  Allows data items within.
19-Feb-02 Sudeshna Sarkar, CSE, IIT Kharagpur1 Arrays, Pointers, Strings Lecture 18 19/2/2002.
Strings. String Literals String literals are enclosed in double quotes: "Put a disk in drive A, then press any key to continue\n“ A string literal may.
ECE 103 Engineering Programming Chapter 29 C Strings, Part 2 Herbert G. Mayer, PSU CS Status 7/30/2014 Initial content copied verbatim from ECE 103 material.
13. Strings. String Literals String literals are enclosed in double quotes: "Put a disk in drive A, then press any key to continue\n“ A string literal.
Chapter 5 Pointers and Arrays Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Strings: C-strings vs. Strings as Objects
Characters, Strings, and the cstring Library
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
Lecture 8 String 1. Concept of strings String and pointers
Characters, Strings, and the cstring Library
Tutorial 8 Pointers and Strings
Pointers.
Pointers.
Strings: C-strings vs. Strings as Objects
Pointers.
String in C++.
EECE.2160 ECE Application Programming
Example: ? str1 str2 _ void salin(char sasaran[], char sumber[]);
ECE 103 Engineering Programming Chapter 51 Random Numbers
Strings String constants String variables Traverse strings.
Strings #include <stdio.h>
Programming Strings.
EECE.2160 ECE Application Programming
Pointers.
Introduction to Problem Solving and Programming
Presentation transcript:

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”; printf(“%s\n”, str); return 0; }

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; }

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; }

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

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

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)

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

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

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

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

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

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

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

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]; }

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