1 Copies at most n1 ch aracters of string in into the 2 buff

1 Copies at most n-1 ch aracters of string in into the 2 buffer pointed to by out If n i s reached, re turns -2. 3 Otherwise returns -1 for ma forme d input and O upon 4 successful completion 6 int copy String N char in, char out int n) Implement a unit test of copyStringN in a main function that exercises its full protective functionality.

Solution

#include <stdio.h>

int copyStringN(char *in, char *out, int n){
int i=0;
if(n < 0){
return -1;
}
for(i=0; i<n; i++){
out[i]=in[i];
}
return 0;
}

int main()
{
char in[7] =\"testing\";
char out[7];
copyStringN(in, out, 7);
printf(\"Output string value is %s\ \", out);

return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Output string value is testing

1

 1 Copies at most n-1 ch aracters of string in into the 2 buffer pointed to by out If n i s reached, re turns -2. 3 Otherwise returns -1 for ma forme d input an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site