
- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
String Copy Program in C
Implementation
Now, we shall see the actual implementation of the program −
#include <stdio.h> int main() { char s1[] = "TajMahal"; // String Given char s2[8]; // Variable to hold value int length = 0; while(s1[length] != '\0') { s2[length] = s1[length]; length++; } s2[length] = '\0'; // Terminate the string printf("Value in s1 = %s \n", s1); printf("Value in s2 = %s \n", s2); return 0; }
Output
Output of this program should be −
Value in s1 = TajMahal Value in s2 = TajMahal
string_programs_in_c.htm
Advertisements