Skip to content

Commit a5d52fa

Browse files
committed
Add hidenstruct
1 parent e8c3e3c commit a5d52fa

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

c/hidenstruct/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "stu.h"
2+
#include <stdio.h>
3+
4+
5+
int main() {
6+
struct stu *s;
7+
s = new_stu();
8+
set_id(s, "114514");
9+
printf("%s", get_id(s));
10+
return 0;
11+
}

c/hidenstruct/stu.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define _CRT_SECURE_NO_WARNINGS
2+
#include <stdlib.h>
3+
#include <string.h>
4+
struct stu {
5+
char id[20];
6+
int score;
7+
};
8+
struct stu *new_stu() {
9+
struct stu *s = malloc(sizeof(struct stu));
10+
return s;
11+
};
12+
void set_id(struct stu *s, const char *id) { strcpy(s->id, id); }
13+
char *get_id(struct stu *s) { return s->id; }

c/hidenstruct/stu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _STU_H
2+
#define _STU_H
3+
struct stu;
4+
extern struct stu *new_stu();
5+
extern void set_id(struct stu *s, const char *id);
6+
extern char *get_id(struct stu *);
7+
#endif // !_STU_H

0 commit comments

Comments
 (0)