Skip to content

Commit 3718835

Browse files
committed
modified: link_table/build.sh
modified: link_table/include/head.h modified: link_table/src/main.c new file: link_test/build.sh modified: link_test/src/main.c new file: test/build.sh new file: test/src/1 new file: test/src/main.c
1 parent 2defdc1 commit 3718835

File tree

8 files changed

+63
-20
lines changed

8 files changed

+63
-20
lines changed

c/link_table/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
rm -rf build
13
mkdir build
24
cd build
35
cmake ..

c/link_table/include/head.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
struct head_link;
4+
struct body_link;

c/link_table/src/main.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
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+
}

c/link_test/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
rm -rf build
3+
mkdir build
4+
cd build
5+
cmake ..
6+
make

c/link_test/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ int main(){
1010
printf("%d\n",test1->num);
1111
return 0;
1212
}
13-

c/test/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
rm -rf build
3+
mkdir build
4+
cd build
5+
cmake ..
6+
make

c/test/src/1

6.48 KB
Binary file not shown.

c/test/src/main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)