Commit 3589a29c authored by Alija Sabic's avatar Alija Sabic
Browse files

Add examples of 7th unit

parent 8f3718c9
/*
============================================================================
Name : 07_company_solution.c
Author : Sabic Alija <sabic@technikum-wien.at>
Version : 0.1
Copyright : Free for all.
Description : Working with structs.
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 100
/****************************************************************************
* Data Structures
***************************************************************************/
struct employee {
char name[MAX_LEN];
int ssn;
int zipcode;
};
struct company {
char name[MAX_LEN];
int uid;
struct employee staff[MAX_LEN];
};
/****************************************************************************
* Function Prototypes
***************************************************************************/
void add_employee(struct employee *p, char *name, int ssn, int zipcode);
void add_employee_c(struct company *p, int pos, char *name, int ssn, int zipcode);
/****************************************************************************
* Application
***************************************************************************/
int main(void) {
struct company hornbach = {.name = "hornbach", .uid = 1 };
// 1. Variant
// hornbach.staff[0].name = "Max Muster";
strcpy(hornbach.staff[0].name, "Max Muster");
hornbach.staff[0].ssn = 1;
hornbach.staff[0].zipcode = 1234;
// 2. Variant
add_employee(&hornbach.staff[1], "Susi Muster", 2, 1234);
// 3. Variant
add_employee_c(&hornbach, 2, "Rob Steel", 989, 2000);
return EXIT_SUCCESS;
}
void add_employee(struct employee *p, char *name, int ssn, int zipcode)
{
// p->name = name;
strcpy(p->name, name);
p->ssn = ssn;
p->zipcode = zipcode;
}
void add_employee_c(struct company *p, int pos, char *name, int ssn, int zipcode)
{
// p->staff[pos].name = name;
strcpy(p->staff[pos].name, name);
p->staff[pos].ssn = ssn;
p->staff[pos].zipcode = zipcode;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment