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

Write a function that takes two pointers to char and copies the content of one a

ID: 3638921 • Letter: W

Question

Write a function that takes two pointers to char and copies the content of one array in reverse order into the other and returns the number of charaters in data1.
The function should be defined as follows,
int reverse (char *data1, char *data2)
Since the array length is not passed into the function it should iterate (cycle) through the values till it sees a NULL ‘’ character

Please put comments on the program as much as you can so I can understand pointers

Explanation / Answer

#include #include int reverse (char *data1, char *data2) { int i=0,t=0; while(data1[i]!=''){i++;}; //first count the number of characters in data1 for(int k=i-1;k>=0;k--) data2[t++]=data1[k]; //then cpy one into the other in reverse return i; //return the length of data1 } int main() { char a[]="adastra"; char b[strlen(a)]; //let the other be with equal len to the first int len; len=reverse(a,b); printf("The original %s reverse %s and the length is %d",a,b,len); return 0; }
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