0% found this document useful (0 votes)
61 views2 pages

Object Oriented Paradigm: Lab 02 Topic(s) : Arrays and Pointers

This document provides instructions for a lab assignment to create a menu-driven C++ program implementing various string manipulation functions that utilize arrays and pointers. The functions include strLength to return the length of a character array, strcpy and strncpy to copy strings, strncat to append strings, strcmp and strncmp to compare strings, strspn to determine the length of a shared prefix, strpbrk to find the first occurrence of characters, strrchr to find the last occurrence of a character, strstr to find the first occurrence of a substring, and strtok to break a string into tokens.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views2 pages

Object Oriented Paradigm: Lab 02 Topic(s) : Arrays and Pointers

This document provides instructions for a lab assignment to create a menu-driven C++ program implementing various string manipulation functions that utilize arrays and pointers. The functions include strLength to return the length of a character array, strcpy and strncpy to copy strings, strncat to append strings, strcmp and strncmp to compare strings, strspn to determine the length of a shared prefix, strpbrk to find the first occurrence of characters, strrchr to find the last occurrence of a character, strstr to find the first occurrence of a substring, and strtok to break a string into tokens.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Object Oriented Paradigm

Lab 02
Topic(s): Arrays and Pointers

Question No. 01

Create a menu driven C++ program with the following functions:

 int strLength(char *s1)


Returns length of a character array.
 char*strcpy(char *s1, char *s2)
Copies all characters of string s2 into array s1. The value of s1 is returned.
 char*strncpy(char *s1, char *s2, int n)
Copies at most n characters of string s2 into array s1. The value of s1 is returned.
 char*strncat(char *s1, const char *s2, int n)
Appends at most n characters of string s2 to array s1. The first character of s2 overwrites
the terminating null character of s1. The value of s1 is returned.
 int strcmp(const char *s1, const char *s2);
Compares the string s1 with the string s2. The function returns 0, less than 0 or greater
than 0 if s1 is equal to, less than or greater than s2, respectively.
 int strncmp(const char *s1, const char *s2, int n);
Compares up to n characters of the string s1 with the string s2.The function returns 0, less
than 0 or greater than 0 if s1 is equal to, less than or greater than s2, respectively.
 int strspn(const char *s1, const char *s2);
Determines and returns the length of the initial segment of string s1 consisting only of
characters contained in string s2.
 char*strpbrk(const char *s1, const char *s2);
Locates the first occurrence in string s1 of any character in string s2. If a character from
string s2 is found, a pointer to the character in string s1 is returned. Otherwise, a NULL
pointer is returned.
 char*strrchr(const char *s, int c);
Locates the last occurrence of c in string s. If c is found, a pointer to c in string s is returned.
Otherwise, a NULL pointer is returned.
 char*strstr(const char *s1, const char *s2);
Locates the first occurrence in string s1 of string s2. If the string is found, a pointer to the
string in s1 is returned. Otherwise, a NULL pointer is returned.

Page 1 of 2
 char*strtok(char *s1, const char *s2);
A sequence of calls to strtok breaks string s1 into “tokens”—logical pieces such as words
in a line of text—separated by characters contained in string s2. The first call contains s1
as the first argument, and subsequent calls to continue tokenizing the same string contain
NULL as the first argument. A pointer to the current token is returned by each call. If there
are no more tokens when the function is called, NULL is returned.

Page 2 of 2

You might also like