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

In C Programming Language Only. Please closely follow the specifications below a

ID: 3699050 • Letter: I

Question

In C Programming Language Only. Please closely follow the specifications below as they are important for my assignment.

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.

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) copies the first n characters from string pointed to by src to the location pointed to by dest. If n > strlen(src) it should just copy the string pointed to by src to dest

Remember for both functions to copy the end of string delimiter ‘’

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: