File tree Expand file tree Collapse file tree 8 files changed +63
-20
lines changed
Expand file tree Collapse file tree 8 files changed +63
-20
lines changed Original file line number Diff line number Diff line change 1+
2+ rm -rf build
13mkdir build
24cd build
35cmake ..
Original file line number Diff line number Diff line change 11#include <stdio.h>
22#include <stdlib.h>
3+ struct head_link ;
4+ struct body_link ;
Original file line number Diff line number Diff line change 11#include "../include/head.h"
2- int main (){
3- struct body_link {
4- void * data ;
5- int type ;
6- struct body_link * next ;
7- };
8- struct head_link {
9- char * name ;
10- struct body_link * head ;
11- struct body_link * * location ;
12- int offset ;
13- struct head_link * next ;
14- };
15- return 0 ;
16- }
172
18- ( struct head_link * ) hcreate (){
3+ * head_link hcreate () {
194 struct head_link * temp ;
205 temp = (struct head_link * )(malloc (sizeof (struct head_link )));
216 temp -> head = (struct body_link * )(malloc (sizeof (struct body_link )));
227 temp -> location = & (temp -> head );
238 temp -> offset = 0 ;
249 return temp ;
2510}
26- int hadd (struct head_link * head_hl ){
11+ int hadd (head_link * head_hl ){
2712 struct head_link * temp ;
2813 temp = (struct head_link * )(malloc (sizeof (struct head_link )));
2914 head_hl -> next = temp ;
30- temp -> head = head_hl -> head ;
31- temp -> location = ( struct body_link * )( malloc ( sizeof ( struct body_link ))) ;
15+ temp -> head = ( struct body_link * )( malloc ( sizeof ( struct body_link ))) ;
16+ * ( temp -> location ) = temp -> head ;
3217 temp -> offset = (head_hl -> offset + 1 );
3318 return 0 ;
3419}
20+ struct body_link {
21+ void * data ;
22+ int type ;
23+ struct body_link * next ;
24+ };
25+ struct head_link {
26+ char * name ;
27+ struct body_link * head ;
28+ struct body_link * * location ;
29+ int offset ;
30+ struct head_link * next ;
31+ };
32+
33+ int main (){
34+ struct head_link * first = hcreate ();
35+ hadd (first );
36+ return 0 ;
37+ }
Original file line number Diff line number Diff line change 1+
2+ rm -rf build
3+ mkdir build
4+ cd build
5+ cmake ..
6+ make
Original file line number Diff line number Diff line change @@ -10,4 +10,3 @@ int main(){
1010 printf ("%d\n" ,test1 -> num );
1111 return 0 ;
1212}
13-
Original file line number Diff line number Diff line change 1+
2+ rm -rf build
3+ mkdir build
4+ cd build
5+ cmake ..
6+ make
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+ #include <string.h>
4+ void strinit (char * * str1 ,const char * str2 ){
5+ * str1 = (char * )malloc (strlen (str2 + 1 ));
6+ sprintf (* str1 ,"%s" ,str2 );
7+ }
8+ struct test {
9+ int type [2 ];
10+ char * name ;
11+ struct test * next ;
12+ };
13+ struct test * add (){
14+ struct test * temp = (struct test * )malloc (sizeof (struct test ));
15+ return temp ;
16+ }
17+ int main (){
18+ struct test * test1 = add ();
19+ test1 -> type [0 ]= 1 ;
20+ //test1->name=(char *)malloc(12);
21+ //sprintf((test1->name),"hello world");
22+ strinit (& (test1 -> name ),"hello world" );
23+ printf ("name:%s\nnum:%d\n" ,(test1 -> name ),(test1 -> type [0 ]));
24+ return 0 ;
25+ }
You can’t perform that action at this time.
0 commit comments