Copying Structure Elements

Following program will illustrate copying structure elements from one structure element to another.

Example

#include <stdio.h>
int main() {
	struct employee {
		char name[10];
		int age;
		float salary;
	};
	struct employee e1 = { "John", 35, 50000.50 };
	struct employee e2, e3;
	/* copying name only from one structure element to another*/
	strcpy(e2.name, e1.name); // strcpy(destination string, source string)
	e2.age = e1.age;
	e2.salary = e1.salary;
	/* copying all elements at one go */
	e3 = e2;
	printf("\n%s %d %f", e1.name, e1.age, e1.salary);
	printf("\n%s %d %f", e2.name, e2.age, e2.salary);
	printf("\n%s %d %f", e3.name, e3.age, e3.salary);
	getchar();
	return 0;
}