Write the following
function without using the
C++ string class or any functions in the
standard library, including strlen().
You may use pointers, pointer
arithmetic or array notation.
PE09 - C-String Functions Write the following function without using the C++ string class or any functions in the standard library, including strlen(). You may use pointers, pointer arithmetic or array notation. Write the function findFirstof(). • The function has two parameters (stri, str2), both pointers to the first character in a C-style string. • You should be able to use literals for each argument. • The function searches through stri, trying to find a match for the first occurance of the C-string pointed to by str2. Return the index inside strl where str2 occurs. • Note that if str2 does not appear in str1, then return - 1. Call the function like this: cout << findFirstOf("eieioh", "eio"); // prints 2 (the index of the second e) cout << findFirstOf("aaaiii", "aia"); // prints -1 (aia not inside aaaiii) In both cases the function returns the index of the first occurrence of str2 inside stri. Exam C++ Quick Reference pe09.cpp 1 #include <cstddef> 1/ size_t for sizes and indexes 2 using namespace std; 3 ITI WRITE YOUR FUNCTION BELOW THIS LINE MITT int findFirstof (const char * si, const char * s2) 5 { 6 int result; 7 // Add your code here 8 return result; 9} CodeCheck Reset
Write the following function without using the C++ string class or any functions in the standard library, including strl
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write the following function without using the C++ string class or any functions in the standard library, including strl
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!