Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and test your own copy characters from string function. The function shoul

ID: 647712 • Letter: W

Question

Write and test your own copy characters from string function. The function should copy count characters from the source string to thedestination string. If the null-character is encountered in source before the specified number of characters has been copied, the function should quit copying after the null-character has been copied. Thedestination string should only be null-terminated if the length of the string in source is less than the number of characters specified. The function should not return anything..

Write and test the following functions. Your function definitions may not include calls to any functions in the library. Be sure to create driver code in main() that is sufficient to test all of your functions with built in code. There should be no user input

Explanation / Answer

#include<iostream>
#include<cstdio>

using namespace std;
typedef unsigned long long ull;

int myStrlen(const char str[])
{
int i=0;
int l=0;
while(str[i]!='')
{
l++;
i++;
}
return l;
}

int myStrcmp(const char str1[], const char str2[])
{
int i=0;
while(str1[i]!='' && str2[i]!='')
{
if(str1[i]-str2[i]!=0)
{
return str1[i]-str2[i];
}
else
{
i++;
}
}
return 0;
}

void myStrncpy(char destination[], const char source[], int count)
{
int i=0;
while(i<count && source[i]!='')
{
destination[i]=source[i];
i++;
}
}

int main()
{
cout<<myStrlen("Big Buck")<<endl;
cout<<myStrcmp("Bold","Soft")<<endl;
char str[10];
myStrncpy(str,"big price",5);
cout<<str<<endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote