C program to copy data from structure into array and from array back into another structure

C program to copy data from structure into array and from array back into another structure


#include <stdio.h>
#include <unistd.h>
#include <string.h>

/*
 * copy a structure into array (memcpy)
 * copy an array into structure (memcpy)
 * retrieve structure's parameters
 */

struct temp {
    char a[100];
    char b[21];
    char c[32];
};

int main()
{
    char a[500];

    struct temp temp1;

    strcpy(temp1.a, "roger federer");
    strcpy(temp1.b, "rafael nadal");
    strcpy(temp1.c, "novak djokovic");

    struct temp temp2;

    memcpy(a, &temp1, sizeof(struct temp));

    memcpy(&temp2, a, sizeof(struct temp));
    printf("%s \n%s \n%s\n",  temp2.a, temp2.b, temp2.c);

    return 0;
}


Neelkanth_221$ ./a.out

roger federer
rafael nadal
novak djokovic