C Programming Language
2nd Edition
ISBN: 9780131103627
Author: Brian W. Kernighan, Dennis M. Ritchie, Dennis Ritchie
Publisher: Prentice Hall
expand_more
expand_more
format_list_bulleted
Question
Chapter 2, Problem 5E
Program Plan Intro
Program Plan-
- Initialize the header files and main() function.
- Ask the user to enter the two strings.
- To define the function any(char[], char[]) to find the position of string2 in string1.
- Finally prints the position.
Summary Introduction- The program takes two input string and finds out the position of string2 in string1.
Program Description- The purpose of the program is to take two input strings namely string1 and string2 and print the position of string2 in string1 by using the fullowing function-
any(s1, s2).
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a c++ program:
NOTE: Pointers must be used to solve the following problem.
Write a function createPassword()with no return value to randomly select 8 capital letters from the alphabet. The function receives the address of the first characters of the password string as parameter.
Hint:Declare a characters string that contains all the capital letters of the alphabet and use the index values of the characters in the string for random selection of characters, e.g.
5char alpha [27] = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;char *pAlpha = alpha;
Display the password from the main()function.Write a function replaceVowels()with no return value to replace all the vowels (A, E, I, O, U) that have been selected with a symbol from the list ($ % @ # &). That is, A must be replaced by $, E replaced by %, I must be replaced by @, O replaced by #, and U must be replaced by &. The function receives the address of the first characters of the password string as parameter. Display the password again…
C Program Functions using Pointers
Create a function modify that accepts an integer and divides the integer by 2 if it is even. If the integer is odd, add one and divide it by 2. The function does not return anything.
In the main function, write a program that asks for an integer input and call the modify function by passing in the reference of that variable as a parameter.
An initial code is provided for you. Just fill in the blanks.
Input
1. One line containing an integer input
Output
Enter a number: 5
Before: 5
After: 3
Complete the following function using pass-by-reference: void findMax(int &max, int a) which assigns value ‘a’ to ‘max’ if a > max. Write a pseudo-code then implement a program in C language to find the maximum in a sequence of numbers using this function.
Chapter 2 Solutions
C Programming Language
Ch. 2 - Prob. 1ECh. 2 - Write a loop equivalent to the for loop above...Ch. 2 - Write the function htoi(s), which converts a suing...Ch. 2 - Write an alternate version of squeeze(s1,s2) that...Ch. 2 - Prob. 5ECh. 2 - Prob. 6ECh. 2 - Prob. 7ECh. 2 - Prob. 8ECh. 2 - Prob. 9ECh. 2 - Rewrite the function lower, which converts upper...
Knowledge Booster
Similar questions
- In C++ Write a recursive function that displays a string reversely on the console using the following header:void reverseDisplay(const string& s) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forwardC++ Pointers must be used to solve the following problem. Write a function createPassword() with no return value to randomly select 8 capital letters from the alphabet. The function receives the address of the first characters of the password string as parameter. Hint: Declare a characters string that contains all the capital letters of the alphabet and use the index values of the characters in the string for random selection of characters, e.g.char alpha [27] = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;char *pAlpha = alpha; Display the password from the main() function. Write a function replaceVowels() with no return value to replace all the vowels (A, E, I, O, U) that have been selected with a symbol from the list ($ % @ # &). That is, A must be replaced by $, E replaced by %, I mustbe replaced by @, O replaced by #, and U must be replaced by &. The function receives the address of the first characters of the password string as parameter. Display the password agin from the main()…arrow_forwardWrite a function recursively_count_vowels() which accepts a pointer to a string, and any other parameters you see fit, and recursively counts the number of vowels in the provided string. This function should return the number of vowels in the string. (programming language c)arrow_forward
- Write in C Language Description Please finish function between. Function between have two parameter a and b which are both the pointer point to integer. Function between return thesummation of all integer after pointer a and before pointer b. Function int between(int *a, int *b){}arrow_forwardIn a function aFunction, we have 2 values: num1 (float type), num2 (int type) declared locally and assigned to 2.1 and 6. Write code segment to return the two values from function aFunction.arrow_forwardWrite in C++ When you're processing data, it’s useful to break up a text string into pieces using a delimiter. Write a function split() that takes a string, splits it at every occurrence of a delimiter, and then populates an array of strings with the split pieces, up to the provided maximum number of pieces. Function specifications: Name: split() Parameters (Your function should accept these parameters IN THIS ORDER): input_string string: The text string containing data separated by a delimiter separator char: The delimiter marking the location where the string should be split up arr string array: The array that will be used to store the input text string's individual string pieces arr_size int: The number of elements that can be stored in the array Return Value: int: The number of pieces the input text string was split into Note: No input will have delimiters in the beginning or the end of the string. (Eg: ",apple, orange" OR "apple, orange,") No input will have multiple…arrow_forward
- Write a C++ program that asks for two lowercase characters. Pass the two entered characters, using pointers, to a function named capit(). The capit() function should capitalize the two letters and return the capitalized values to the calling function through its pointer arguments. The calling function should then display all four lettersarrow_forwardThis is what I currently have : void displaySentence(char * sentence); char * sentence;arrow_forward1. Write a program in C to print all combinations/permutations of a particular string using pointers. must have unique 6 elements. An example: UVWXYZ. (An alternative, single permutation for this example would be VUWXYZ.) You create the original string by hand. The stringarrow_forward
- Q4. Write a program that read 2 matrices and has a function which finds their sum. Q5. Write a program that read 2 matrices and has a function which finds their multiplication. Q6. Write a program that handles a list of numbers where it has the following functions - Function that finds their average and sum - Function that finds their maximum and minimum - Function that search for a given number in that list. - Function that count the occurrence of a given number in that list. Then the program should do the following: - Read the list - Find the average and the sum of that list - Find the minimum and the maximum of that list - Count the occurrence of a given number in that list.arrow_forwardIn C++, Define a structure Triangle that contains three Point members. Write a function that computes the perimeter of a Triangle. Write a program that reads the coordinates of the points, calls your function, and displays the result. Contains two arrays of three double values each, one for the x-coordinates and one for the y-coordinates. Must contain two arrays of three double values each, one for the x-coordinates and one for the y-coordinates.arrow_forward1. Write the program to implement Binary Search Algorithm in C++. Use the Binary Search Function that takes the array A, the first index (first), the last index (last) and the search key V as inputs, and the function will return the index of the searched key. If the function returns -1 then display a message in main, that the data is not found, but if it returns a non-zero number, then display the index of the searched key. Make sure to supply a sorted array as input from main. You must give your program along with the code outputs.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr