employ2.html

来自「Thinking in C, 全世界非常有名的学习C语言的书籍。本源代码含有该书」· HTML 代码 · 共 66 行

HTML
66
字号
<html><font size="+1"><pre>
/* employ2.c */
#include "employ2.h"
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

struct Employee* createEmployee(char* last, char* first, char* title, int salary) {
    struct Employee* p = malloc(sizeof(struct Employee));
    if (p != NULL) {
        strcpy(p-&gt;last, last);
        strcpy(p-&gt;first, first);
        strcpy(p-&gt;title, title);
        p-&gt;salary = salary;
    }
    return p;
}

char* getLast(struct Employee* p) {
    return p ? p-&gt;last : "";
}

char* getFirst(struct Employee* p) {
    return p ? p-&gt;first : "";
}

char* getTitle(struct Employee* p) {
    return p ? p-&gt;title : "";
}

int getSalary(struct Employee* p) {
    return p ? p-&gt;salary : 0;
}

void setLast(struct Employee* p, char* last) {
    if (p != NULL)
        strcpy(p-&gt;last, last);
}

void setFirst(struct Employee* p, char* first) {
    if (p != NULL)
        strcpy(p-&gt;first, first);
}

void setTitle(struct Employee* p, char* title) {
    if (p != NULL)
        strcpy(p-&gt;title, title);
}

void setSalary(struct Employee* p, int salary) {
    if (p != NULL)
        p-&gt;salary = salary;
}

void printEmployee(struct Employee* p) {
    putchar('{');
    if (p != NULL) {
        printf("%s,%s,%s,%d",
               p-&gt;last,
               p-&gt;first,
               p-&gt;title,
               p-&gt;salary);
    }
    putchar('}');
}
</pre></font></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?