Skip to content

Commit 076f498

Browse files
committed
new file: CMakeLists.txt
new file: build.sh new file: include/head.hpp new file: include/onebot.h new file: include/str.h new file: src/main.cpp new file: src/onebot.cpp new file: src/str.cpp
1 parent 52c2d90 commit 076f498

File tree

8 files changed

+76
-0
lines changed

8 files changed

+76
-0
lines changed

cpp/test/CMakeLists.txt

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

cpp/test/build.sh

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

cpp/test/include/head.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <cstdio>
3+
#include <cstdlib>
4+
#include <cstring>
5+
//extern "C"
6+
//{
7+
#include "../include/str.h"
8+
//}
9+
struct body_link{
10+
int type;
11+
void *data;
12+
struct body_link *next;
13+
};
14+
struct head_link{
15+
int type[2];
16+
char *name;
17+
struct body_link *head;
18+
struct body_link **location;
19+
struct test *next;
20+
};
21+
struct head_link* add(){
22+
struct head_link *temp=(struct head_link*)malloc(sizeof(struct head_link));
23+
return temp;
24+
}

cpp/test/include/onebot.h

Whitespace-only changes.

cpp/test/include/str.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <cstdio>
2+
#include <cstdlib>
3+
#include <cstring>
4+
void strval(char **str1,const char *str2,int type);

cpp/test/src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "../include/head.hpp"
2+
int main(){
3+
struct head_link *test1=add();
4+
test1->type[0]=1;
5+
strval(&(test1->name),"hello ",1);
6+
strval(&(test1->name),"world",2);
7+
strval(&(test1->name),"goodbye world",3);
8+
printf("name:%s\nnum:%d\n",(test1->name),(test1->type[0]));
9+
return 0;
10+
}
11+

cpp/test/src/onebot.cpp

Whitespace-only changes.

cpp/test/src/str.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "../include/str.h"
2+
void strval(char **str1,const char *str2,int type){
3+
switch (type)
4+
{
5+
case 1 : {
6+
*str1=(char *)malloc(strlen(str2+1));
7+
sprintf(*str1,"%s",str2);
8+
printf("case 1 :%s\n",*str1);
9+
break;
10+
}
11+
case 2 : {
12+
*str1 = (char *)realloc(*str1,strlen(*str1)+strlen(str2)+1);
13+
sprintf(*str1,"%s%s",*str1,str2);
14+
printf("case 2 :%s\n",*str1);
15+
}
16+
break;
17+
case 3 : {
18+
free(*str1);
19+
*str1=(char *)malloc(strlen(str2+1));
20+
sprintf(*str1,"%s",str2);
21+
printf("case 3 :%s\n",*str1);
22+
break;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)