-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path47.cpp
26 lines (20 loc) · 901 Bytes
/
47.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*Write a program to copy one string to another using pointer.*/
#include <stdio.h>
int main() {
char source[] = "Suchorit Saha"; // Source string
char destination[50]; // Destination string (large enough to hold the copied string)
// Pointer to source and destination
char *src = source;
char *dest = destination;
// Copying each character from source to destination using pointers
while (*src != '\0') {
*dest = *src; // Copy character from source to destination
src++; // Move the source pointer to the next character
dest++; // Move the destination pointer to the next position
}
*dest = '\0'; // Null-terminate the destination string
// Print both strings to verify the copy
printf("Source String: %s\n", source);
printf("Destination String: %s\n", destination);
return 0;
}