Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C String Functions: strchr, strrchr, strcspn, strspn, strpbrk, strstr, strtok, Study notes of Engineering

This lecture from the introduction to c programming for engineers course covers various c string functions, including strchr, strrchr, strcspn, strspn, strpbrk, strstr, and strtok. The functions are explained with examples and code snippets.

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-ca9
koofers-user-ca9 🇺🇸

5

(1)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #17
Jeffrey Miller, Ph.D.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download C String Functions: strchr, strrchr, strcspn, strspn, strpbrk, strstr, strtok and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

C String Functions

char strchr (const char, int);

Locates the first occurrence of the characterdenoted by the ASCII value of the integerpassed in the string

Returns a pointer to the character in the string ifexists - Returns a NULL pointer if the character is notin the string

C String Functions

size_t strcspn (const char, const char);

Determines and returns the length of the initialsegment of the first string consisting ofcharacters not contained in the second string char *s = “hello world”; char *s2 = “wow”; int length = strcspn(s1, s2); // returns 4

C String Functions

size_t strspn (const char, const char);

Determines and returns the length of the initialsegment of the first string consisting only ofcharacters contained in the second string char *s1 = “heeee haw”; char *s2 = “he”; int length = strspn(s1, s2); // returns 5

C String Functions

char* strstr (const char, const char);

Locates the first occurrence in the first string ofthe second string

If the second string is found in the first string, apointer to the string in the first string is returned - If not, a NULL pointer is returned

C String Functions

char* strtok (char, const char);

Breaks the first string into “tokens” separatedby characters contained in the second string

The first call to this function contains a stringas the first parameter, and subsequent calls tocontinue tokenizing the same string containsNULL as the first parameter - A pointer to the current token is returned byeach call - If there are no more tokens, NULL is returned

Homework

Homework #7 is posted!