
Concept explainers
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...

Want to see the full answer?
Check out a sample textbook solution
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- Using MATLAB symbolic toolbox, given these 3 equations, how would you solve for mu = function(theta), making sure that there are no mu's on the right hand side, making sure theta-dot-dot, theta-dot-squared- and N aren't in the final answer either.arrow_forwardAfter playing our giving implementation, your task is to implement Dinning Philosophers with semaphore in C, by including and Your implementation will require creating five philosophers, each identified by a number 0.4. Each philosopher will run as a separate thread. Create threads using Pthreads as discussed in the Lecture slides on Chapter 4 and Practice Lab on Threads. Your solution needs to accomplish the following: Implement in C (15 points) 1. dp1.c - You are to provide your solution to this assignment as a single C program named 'dp1.c using semaphore. Explain in you code (as comments) that the dead lock will happen or not. If there is a possible deadlock, you can simply solve the deadlock by pick the fork in order like the first solution in our slides. Solve Deadlock by Footman (15 points) 1. Here is a new solution to overcome the deadlock. The Dining Philosophers decide to hire a footman whose task to allow only four philosophers to sit on the table. When entering and…arrow_forward8.4 Self-Bias Configuration 20. Determine Zi. Zo. and A,, for the network of Fig. 8.73 if gf, = 3000 μS and gos = 50 μs. 21. Determine Z, Zo, and A, for the network of Fig. 8.73 if the 20-uF capacitor is removed and the parameters of the network are the same as in Problem 20. Compare results with those of Problem 20. +12 V 3.3 ΚΩ HE C₂ Vo Z Zo C₁ 10 ΜΩ Z₁ 1.1 ΚΩ Cs 20 µF FIG. 8.73 Problems 20, 21, 22, and 59.arrow_forward
- 21. Determine Zi, Zo, and A, for the network of Fig. 8.73 if the 20-μF capacitor is removed and the parameters of the network are the same as in Problem 20. Compare results with those of Problem 20. +12 V 3.3 ΚΩ +6 C₂ C₁ Z₁ 10 ΜΩ 1.1 ΚΩ Cs 20 μF FIG. 8.73 Zoarrow_forwardNinth Edition Determine Zi, Zo and Av 20 V Zi + 1 ΜΩ 2 ΚΩ HH Z IDSS= 6MA Vp=-6V Yos = 40μS 20 and 47arrow_forwardWhat is the worst case time complexity of the following algorithm for i = 1 to x do for j = 2^((i-1)x) to 2^(in) do print(i,j)arrow_forward
- Prove for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forwardI need to make a parallel version of this sequential codearrow_forwardI need to make a parallel version of this sequential code.arrow_forward
- Benefits of using arrays as instance variables: What are the advantages of incorporating arrays as instance variables within a class? Initializing and managing arrays: How do you initialize and manage arrays within class constructors and mutators (setters)? Example of using arrays as instance variables: Share an example where you have used arrays as instance variables and discuss its application in a real-world scenario. Common mistakes with arrays as instance variables: What are some common mistakes to avoid when working with arrays as instance variables? Information hiding violations: What is the potential violation of information hiding when using arrays as instance variables? How can this be resolved?arrow_forwardDo you think that computers should replace teachers? Give three references with your answer.arrow_forwardIs online learning or face to face learning better to teach students around the around the world? Give reasons for your answer and provide two references with your response. What are benefits of both online learning and face to face learning ? Give two references with your answer. How does online learning and face to face learning affects students around the world? Give two references with your answer.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT





