Write a function called s to extract a portion of a character string. The function should be called as follows:
s
where S is the character string from which you are extracting the substring, S is an index number into S indicating the first character of the S, c is the number of characters to be extracted from the S string, and r is an array of characters that is to contain the extracted substring.
For example, the call
s
extracts the substring̎ (three characters starting with character number 4) from the string̎ and places the result in r.
Be certain the function inserts a null character at the end of the substring in the result array. Also, have the function check that the requested number of characters does, in fact, exist m the string. If this is not the case, have the function end the substring when it reaches the end of the source string. So, for example, a call such as
s
should just place the string “words” inside the result array, even though 20 characters were requested by the call.
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Programming in C
Additional Engineering Textbook Solutions
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Starting Out with C++: Early Objects
Starting Out with Java: Early Objects (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting out with Visual C# (4th Edition)
Starting Out With Visual Basic (8th Edition)
- Write a function named(difference), that accepts an integer one-dimensional array and its size, returns the difference between the largest element and the smallest element. e.g. the array is [1,7,13,22,15,6,4,3,2,9,21] the output is:21arrow_forwardWrite a function that gets an array as a parameter, sorts it in an ascending fashion and returns the number of elements that did not change position in the sort (they were originally in the right position). Use c code int sortASC(int* myArray, int size) if array ={ 2, 3, 1, 0, -1} after calling the function the array should become {-1, 0, 1, 2 , 3 } and the function should return 1 (only one element has not changed place in the array)arrow_forwardWrite a function which takes two arguments: a) A NULL-terminated array of pointer to function, and b) a char *. Each function in the array of function parameter takes the string as its argument and returns a string. The returned strings from the function calls should be copied (create a copy of the string) into an array of pointer to char (NULL terminated!) which YOUR function returns. Make the returned array of pointer EXACTLY the right size (count first, then allocate). Use indices to traverse the array of function pointers and the constructed array of pointers to char.arrow_forward
- Write a function using python: diceSim(D1,D2,trials) that takes as input the number of sides on die 1 (D1) and die2 (D2) and the number of trials. Your function should repeatedly sum pairs of random numbers between 1 and D1 and 1 and D2 and keep track of how many times each sum occurs. The function returns a numpy array with the fraction each sum of rolls occured. Since the numbers are chosen at random, the fractions will differ some from run to run. One run of the function print(p22.diceSim(6,6,10000)) resulted in: [0. 0. 0.0259 0.0615 0.0791 0.1086 0.139 0.1633 0.1385 0.114 0.0833 0.0587 0.0281]arrow_forwardPLease! in c++ Write a function named “getNonNegativeSum” that takes in 4 input parameters: -a pointer to thearray of integers-its size, -the index tostart the sum from -the count of how many numbers from that starting index It will return the sum of all values from the startingindex with the number count of how many. It will add to the sum if the number in the array is positiveand skip all negative values. If there is an error in the indexor not enough numbers to count, it will return -1. For example,int numList[] = {10, 20, -1, 30}; If the starting index is 1 and the count of 3, it will return 50 If the starting index is 2 and the count of 2, it will return 30 If the starting index is -1 and the count of 2, it will return -1 If the starting index is 2and the count of 5, it will return -1.int priceList[] = {10, 20, 30, -1, 40}; If the starting index is 0, and the count is 1, it will return 10 If the starting index is 1, and the count is 3, itwill return 50 If the starting index is 0,…arrow_forwardWrite a function that takes two inputs: - An array of doubles named data. - A scalar double (single number) named threshold. Your function should have one output: - A double named below. The value of below should be the number of elements in data that have a value less than threshold. Please use MATLABarrow_forward
- Imagine that you are a biomedical engineer analyzing DNA sequences. You have numerical measurements from two different measurement sources, m1 and m2, both of which are arrays. Write a function named dna that takes these two arrays as inputs. It should return a character array string of nucleotides (represented by the letters A, C, G and T). For a given index, i, the nucleotide in the string is: - ‘A’ if m1(i) >= 0 and m2(i) >= 0 - ‘C’ if m1(i) < 0 and m2(i) >= 0 - ‘G’ if m1(i) >= 0 and m2(i) < 0 - ‘T’ if m1(i) < 0 and m2(i) < 0 code to call the function m1 = [-2 -3 2.5 0.3]; m2 = [1.1 2.1 -0.8 0.1]; sequecne = dna(m1,m2); function dna Please use MATLABarrow_forwardWrite a function called largest_sum_sequence() that accepts an array of signed integers and the number of items in the array as parameters, and returns the largest sum of a sequence of numbers in the array. A sequence is defined as a single item or multiple items that are in consecutive adjacent memory locations. Example 1: 9 3 -1 7 -12 largest sum in sequence is 18 [9, 3, -1, 7] Example 2: -77 3 -2 1 largest sum in sequence is 3 [3]arrow_forwardWrite a C Program for this question Write a function called mergeArrays. It should accept three integer arrays: A, B and C, and two integers m and n representing the sizes of the first two arrays. It can be assumed that the size of C is m+n. Arrays A and B contains integers that are already sorted in the ascending order (i.e. increasing order). Your function must combine all the numbers in A and B and store them C in such a way that C is also sorted in the ascending order. Here is an example to clarify the requirements. In this case, the sizes of A and B are 6 and 4 respectively. SAMPLE A : 0 4 5 5 7 9 B: -1 0 3 6 C: -1 0 0 3 4 5 5 6 7 9 Then you have to separate odd and even integers in two separate arrays respectively.arrow_forward
- Write a c++ function is called IsContain Given two arrays A and B with equal size n, write a C++ function that returns true if every element of A is found in B; otherwise returns falsearrow_forwardCreate a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forwardSet up a user defined function for finding square root If the supplied number is not negative the function should find the square root of the value passed value using the proper Numpy function and return it rounded to 3 decimal places. If the passed number is negative, then the function should return a string with the value of the square root of the positive portion of the number concatenated with the letter ‘i’ to the right Set seed to 1 and create a Numpy array of 6 randomly generated integer numbers between -10 to 10 Iterate over the values of the Numpy array prepare a report, Use f-string formatting and Use the user defined function for the Square-root column Column names: Row, Number, Running Sum, and Square-rootarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr