Q:

Write C program to copy one string to another string

belongs to collection: C language Pointer Exercises

0

Write C program to copy one string to another string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter any string: TechStudy-The Complete Debugging Solution

First string = TechStudy-The Complete Debugging Solution

Second string = TechStudy-The Complete Debugging Solution

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to concatenate two strings using p... >>
<< Write C Program to find length of string using poi...