EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

Question
Book Icon
Chapter 1, Problem 5E
Program Plan Intro

String functions:

The string functions and their purpose is shown below:

  • The function “strcpy(s1,s2)” copies string “s2” into “s1”.
  • The function “strcat(s1,s2)” concatenates string “s2” on end of “s1”.
  • The function “strlen(s1)” returns length of “s1”.
  • The function “strchr(s1,ch)” would return a pointer to first presence of character “ch” in string “s1” .

Explanation of Solution

//(b)strcmp function

The function “strcmp()” compares two strings. It takes header pointer of two strings as function arguments, it checks until the string reaches null and compares both strings by comparing each character at corresonding position ...

Explanation of Solution

//(c) Strcat function

The function “Strcat()” copies data of “s2” to “s1”. To do so, it first reaches end of the string “s1” using recursive calls “Strcat(++s1, s2)”...

Explanation of Solution

//(d) Strchr function

The function “Strchr()” searches for a particular character in string. It iterates through character array and compares each character with search character, if it matches then the index of match is returned.

char* Strchr(char *s, char ch)

{

/*It checks for each character in string and compares it with that of the search string until the     character array reaches null or it becomes empty. If a match is obtained, then store index of match*/

for ( ; *s != ch && *s != '\0'; s++);

  //Return index of matched character

  return *s == ch ? s : 0;

}

The main function defines two character array and tests the functions “Strlen()”, “Strcmp()”, “Strchr()”, “Strcat()” and displays the final result based on the return values of each functions

int main()

{

//Declare the variable

int ret;

//Declare character arrays

char str1[100] = "Drowning";

char *str2 = "Boat";

//Declare pointer of string

char *pch;

//Declare variables

int length ;

//Call the function "strlen()" and store the return value

length = Strlen(str1);

//Display first string

cout<<"String1: ";

puts(str1);

//Display second string

cout<<"String2: ";

puts(str2);

//Display the length of first string

cout<<"\nLength of String1 :"<< length;

//Call the function "Strcmp()" and store the return value of function

ret = Strcmp(str1,str2);

If return value is less than 0, then “String1” is less than “String2”. If return value is greater than 0, then “String2” is less than “String1”, else “String1” equals “String2”.

if(ret < 0)

{

  //Display the result

  cout<<"\nString1 is less than String2";

}

If return value is greater than 0, then “String2” is less than “String1”

else if(ret > 0)

{

  //Display the result

  cout<<"\nString2 is less than String1";

}

If “String1” equals “String2”, display the equal message

//"String1" equals "String2"

else

{

  //Display the result

  cout<<"\n String1 equals String2";

}

The function “Strchr()” is called with “str1” and search character “r” as argument, function’ sreturn value is stored, that is , the value of matched index...

Blurred answer
Students have asked these similar questions
Need this expression solved for mu. This can be done using a symbolic toolbox, however it needs to end up being mu = function (theta, m, L, g). If using MATLAB or something similar, run the code to make sure it works.
A business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution.  will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem.  mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally,  must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment.   CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…
A business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution.  will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem.  mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally,  must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment.   CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT