Write a c program to copy data one structure to another structure
BM Balmiki Mandal 16 Dec 2022 13 views 0 comments C Programming

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

"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

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026