






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 10
This page cannot be seen from the preview
Don't miss anything!
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
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
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
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
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