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
- 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
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
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…
Write a user-defined function that compares two string with each other.
If first one is equal to second returns 0, greater than second returns 1 and less than second
returns -1.
Your function prototype is int compareString(char *, char *)
Write another user-defined function which gets a pointer to a character string containing the
name of months. Function will return the name of month depending on its arguments.
For example :
if it gets 2 it will return February.
if it gets O it will return incorrect month
if it gets 9 it will return September
Your function prototype is char "month_name(int n)
Write a main function to test your functions. Do not use library functions to compare two
strings.
Example Input:
Ankara
Antalya
4
Example Output:
-1
April
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
- 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.arrow_forwardIN C PROGRAMMING LANGUAGE: Please write a pointer version of squeeze() named psqueeze(char *s, char c) which removes c from the string s.arrow_forwardComputer Science In C++ use the following STL algorithms: reverse, rotate, and shuffle. Write versions of these functions using the same parameters as the original functions but using your own definition of the function body. Use each function at least three different times in a test program to make sure the function operates properly. The data sets you use for testing should contain at least twenty elementsarrow_forward
- C++ 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_forwardIn 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_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++ 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_forwardWrite a function whose prototype is void exchange(int *p, int *q);that takes two pointers to integer variables and exchanges the values in those variables.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_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_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_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