File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ; }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments