Skip to content

Commit 30a5d0c

Browse files
committed
new file: bit/1
new file: bit/1.c new file: bit/limit/main.c new file: malloc/1.c renamed: uniconbit/main.c -> unionbit/main.c new file: ../cpp/strlib/CMakeLists.txt new file: ../cpp/strlib/build.sh new file: ../cpp/strlib/include/str.h new file: ../cpp/strlib/src/str.cpp new file: ../cpp/strlib/src/test.cpp new file: ../cpp/test2/main.c
1 parent 76c9c5e commit 30a5d0c

File tree

11 files changed

+125
-0
lines changed

11 files changed

+125
-0
lines changed

c/bit/1

6.2 KB
Binary file not shown.

c/bit/1.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
const char *u2word(int u);
5+
int main(){
6+
int a = 0x52B3;
7+
printf("%s\n",u2word(a));
8+
}
9+
const char *u2word(int u){
10+
char *temp=(char *)malloc(sizeof(int));
11+
sprintf(temp,"%X",u);
12+
printf("\\u%s\n",temp);
13+
temp[0]='\\';
14+
temp[1]='u';
15+
return temp;
16+
}

c/bit/limit/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <limits.h>
3+
4+
int main(){
5+
printf("One Byte is %d bit\n",CHAR_BIT);
6+
7+
printf("The min of signed char is %d\n",SCHAR_MIN);
8+
printf("The max of signed char is %d\n",SCHAR_MAX);
9+
printf("The max of unsigned char is %u\n",UCHAR_MAX);
10+
11+
printf("The min of signed short is %d\n",SHRT_MIN);
12+
printf("The max of signed short is %d\n",SHRT_MAX);
13+
printf("The max of unsigned short is %u\n",USHRT_MAX);
14+
15+
printf("The min of signed int is %d\n",INT_MIN);
16+
printf("The max of signed int is %d\n",INT_MAX);
17+
printf("The max of unsigned int is %u\n",UINT_MAX);
18+
19+
printf("The min of signed long is %ld\n",LONG_MIN);
20+
printf("The max of signed long is %ld\n",LONG_MAX);
21+
printf("The max of unsigned long is %lu\n",ULONG_MAX);
22+
23+
printf("The min of signed long long is %lld\n",LLONG_MIN);
24+
printf("The max of signed long long is %lld\n",LLONG_MAX);
25+
printf("The max of unsigned long long is %llu\n",ULLONG_MAX);
26+
27+
}

c/malloc/1.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
int main(){
4+
int *a=(int *)malloc(sizeof(int));
5+
*a=4;
6+
printf("a:%p\n",a);
7+
{
8+
free(a);
9+
int *b=(int *)malloc(sizeof(int));
10+
printf("a:%p\n",a);
11+
printf("b:%p\n",b);
12+
}
13+
printf("%d\n",*a);
14+
}
File renamed without changes.

cpp/strlib/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/strlib/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/strlib/include/str.h

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

cpp/strlib/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+
}

cpp/strlib/src/test.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+

0 commit comments

Comments
 (0)