Write a c program to copy data one structure to another structure

17 Dec 2022 Balmiki Mandal 0 C Programming

"Write a c program to copy data from one structure to another structure" means to create a C program that takes the data stored in one instance of a structure and copies it to another instance of a different structure.

This involves reading the data from the fields of the source structure and assigning it to the corresponding fields of the destination structure. Depending on the types of data in the structures, this could involve using functions like strcpy() for strings or simply assigning values directly for integer or character types.

The goal is to create a program that can easily transfer data from one instance of a structure to another instance of a similar structure, without the need for manual data entry.

 

Write a c program to copy data from one structure to another structure

#include<stdio.h>
struct st
{
int roll_num;
char name[10];
float t_marks;
};
void main()
{
    struct st s1={192,"BALMIKI",85.4},s2;
    printf("Secufully copy data to another structure:\n");
    // s2.roll_num=s1.roll_num;
    // s2.name[10]=s1.name[10];
    // s2.t_marks=s1.t_marks;
    s2=s1;
    printf("First structure:%d  %s  %f\n",s1.roll_num,s1.name,s1.t_marks);
    printf("Second structure:%d  %s  %f\n",s2.roll_num,s2.name,s2.t_marks);
}

Output:

 successfully  copy data to another structure:

First structure: 192  BALMIKI  85.400002

Second structure: 192  BALMIKI  85.400002

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.