Code:
/*
* File: Structplay.c
* Author: jim
*
* Created on June 14, 2010, 10:50 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
typedef struct{
int feet;
double inches;
}Height;
typedef struct{
char *name;
Height height;
int weight;
int age;
}personal_info;
void SwapClient(personal_info *clientA,personal_info *clientB);
int main(void) {
personal_info client [10];
int i;
i = 1;
client[0].name = "Wilson, Bob";
client[0].height.feet = 5;
client[0].height.inches = 10.5;
client[0].weight = 185;
client[0].age = 46;
client[1].name = "Jones Shirley";
client[1].height.feet = 5;
client[1].height.inches = 2.25;
client[1].weight = 121;
client[1].age = 29;
printf("before the swap ---------------------------\n\n");
printf("Client:%s, height %d foot %.2f inches, weight = %d, age = %d\n",
client[0].name, client[0].height.feet,client[0].height.inches,
client[0].weight, client[0].age);
printf("Client:%s, height %d foot %.2f inches, weight = %d, age = %d\n\n",
client[1].name, client[1].height.feet,client[1].height.inches,
client[1].weight, client[1].age);
SwapClient(client,client+1);
printf("after the swap ---------------------------\n\n");
printf("Client:%s, height %d foot %.2f inches, weight = %d, age = %d\n",
client[0].name, client[0].height.feet,client[0].height.inches,
client[0].weight, client[0].age);
printf("Client:%s, height %d foot %.2f inches, weight = %d, age = %d\n\n",
client[1].name, client[1].height.feet,client[1].height.inches,
client[1].weight, client[1].age);
return 0;
}
void SwapClient(personal_info *clientA,personal_info *clientB){
personal_info tempClient;
tempClient = *clientA;
*clientA = *clientB;
*clientB = tempClient;
}
/*
* Sample output------------------------------------
before the swap ---------------------------
Client:Wilson, Bob, height 5 foot 10.50 inches, weight = 185, age = 46
Client:Jones Shirley, height 5 foot 2.25 inches, weight = 121, age = 29
after the swap ---------------------------
Client:Jones Shirley, height 5 foot 2.25 inches, weight = 121, age = 29
Client:Wilson, Bob, height 5 foot 10.50 inches, weight = 185, age = 46
Press [Enter] to close the terminal ...
*/
I know I shouldn't skim through a subject like structs and just start coding but I couldn't help my excitement. I will do a more thorough examination of the references in the next few days.