Write the implementations of functions copy1 and copy2 for copying strings. copy1 uses array index notation. copy2 uses Pointers and Pointer Arithmetic. #include #define SIZE 10 void copy1(char* s1, const char* s2); // prototype void copy2(char* s1, const char* s2); // prototype int main(void) { char string1[SIZE]; // create array string1 char *string2 = "Hello"; // create a pointer to a string copy1(string1, string2); printf("string1 = %s\n", string1); char string3[SIZE]; // create array string3 char string4[] = "Good Bye"; // create an array containing a string copy2(string3, string4); printf("string3 = %s\n", string3); } void copy1(char* s1, const char* s2) { //Implement copying string using array index notation } void copy2(char* s1, const char* s2) { //Implement copying string using Pointers and Pointer Arithmetic }
Write the implementations of functions
copy1 and copy2 for copying strings. copy1 uses array index notation. copy2 uses Pointers and
Pointer Arithmetic.
#include <stdio.h>
#define SIZE 10
void copy1(char* s1, const char* s2); // prototype
void copy2(char* s1, const char* s2); // prototype
int main(void)
{
char string1[SIZE]; // create array string1
char *string2 = "Hello"; // create a pointer to a string
copy1(string1, string2);
printf("string1 = %s\n", string1);
char string3[SIZE]; // create array string3
char string4[] = "Good Bye"; // create an array containing a string
copy2(string3, string4);
printf("string3 = %s\n", string3);
}
void copy1(char* s1, const char* s2)
{
//Implement copying string using array index notation
}
void copy2(char* s1, const char* s2)
{
//Implement copying string using Pointers and Pointer Arithmetic
}
Step by step
Solved in 4 steps with 2 images