Write C program to copy one string to another string

Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
#define MAX_SIZE 100 // Maximum size of the string
 
int main()
{
    char text1[MAX_SIZE], text2[MAX_SIZE];
    char * str1 = text1;
    char * str2 = text2;
 
    // Inputting string from user
    printf("Enter any string: ");
    gets(text1);
 
    // Coping text1 to text2 character by character
    while(*(str2++) = *(str1++));
 
    printf("First string = %s\n", text1);
    printf("Second string = %s\n", text2);
 
    return 0;
}

Result

Write C program to copy one string to another string
Write C program to copy one string to another string

Leave a Comment