Skip to content

Commit 671f442

Browse files
committed
new file: CMakeLists.txt
modified: build.sh new file: include/head.h deleted: src/1 modified: src/main.c
1 parent 3718835 commit 671f442

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

c/test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROJECT(TEST)
2+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
3+
INCLUDE_DIRECTORIES(./include)
4+
AUX_SOURCE_DIRECTORY(./src DIR_SRC)
5+
ADD_EXECUTABLE(./bin ${DIR_SRC})

c/test/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ mkdir build
44
cd build
55
cmake ..
66
make
7+
./bin

c/test/include/head.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
void strval(char **str1,const char *str2,int type){
5+
switch (type)
6+
{
7+
case 1 : {
8+
*str1=(char *)malloc(strlen(str2+1));
9+
sprintf(*str1,"%s",str2);
10+
printf("case 1 :%s\n",*str1);
11+
break;
12+
}
13+
case 2 : {
14+
*str1 = (char *)realloc(*str1,strlen(*str1)+strlen(str2)+1);
15+
sprintf(*str1,"%s%s",*str1,str2);
16+
printf("case 2 :%s\n",*str1);
17+
}
18+
break;
19+
case 3 : {
20+
free(*str1);
21+
*str1=(char *)malloc(strlen(str2+1));
22+
sprintf(*str1,"%s",str2);
23+
printf("case 3 :%s\n",*str1);
24+
break;
25+
}
26+
}
27+
}
28+
struct test{
29+
int type[2];
30+
char *name;
31+
struct test *next;
32+
};
33+
struct test* add(){
34+
struct test *temp=(struct test*)malloc(sizeof(struct test));
35+
return temp;
36+
}

c/test/src/1

-6.48 KB
Binary file not shown.

c/test/src/main.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
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-
}
1+
#include "../include/head.h"
172
int main(){
183
struct test *test1=add();
194
test1->type[0]=1;
20-
//test1->name=(char *)malloc(12);
21-
//sprintf((test1->name),"hello world");
22-
strinit(&(test1->name),"hello world");
5+
strval(&(test1->name),"hello ",1);
6+
strval(&(test1->name),"world",2);
7+
strval(&(test1->name),"goodbye world",3);
238
printf("name:%s\nnum:%d\n",(test1->name),(test1->type[0]));
249
return 0;
2510
}

0 commit comments

Comments
 (0)