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

Lab 9 (this is to be turned in) You are to write two functions char *reverse (ch

ID: 3741497 • Letter: L

Question

Lab 9 (this is to be turned in) You are to write two functions char *reverse (char *dest, char *src) And char* mystrNcpy(char *dest, char *src, int n) You should not use any standard library functions in your functions. These two function can be used in Lab8 The function char * reverse(char *dest, char *src); copies the reverse of the string pointed to by src to the memory location pointed to by dest (note src could equal dest) The function char * mystrNcpy(char "dest, char *src, int n): if n strlen(src) it should just copy the string pointed to by sre to dest Remember for both functions to copy the end of string delimiter 10

Explanation / Answer

#include <stdio.h>
#include <string.h>
char* reverse(char *dest, char *src);
char* mystrNcpy(char *dest, char *src, int n);
int main()
{
char src[100]="Hai Hello";
char dest[100];
printf("%s ",reverse(dest, src));
printf("%s ",mystrNcpy(dest, src, strlen(src)));

return 0;
}
char* reverse(char *dest, char *src) {
int n = 0,j=0,i;
while(src[n]!='') {
n++;
}
for(i=n-1;i>=0;i--,j++) {
dest[j]=src[i];
}
dest[j]='';
return dest;
}
char* mystrNcpy(char *dest, char *src, int n) {
int i = 0;
for(i=0;i<n;i++) {
dest[i]=src[i];
}
dest[i]='';
return dest;
}

Output: