Skip to content

Commit 5ad86ee

Browse files
committed
Code Formatting
1 parent fb78dd1 commit 5ad86ee

File tree

47 files changed

+483
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+483
-398
lines changed

c/bit/limit/main.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
#include <stdio.h>
22
#include <limits.h>
33

4-
int main(){
5-
printf("One Byte is %d bit\n",CHAR_BIT);
4+
int main()
5+
{
6+
printf("One Byte is %d bit\n", CHAR_BIT);
67

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);
8+
printf("The min of signed char is %d\n", SCHAR_MIN);
9+
printf("The max of signed char is %d\n", SCHAR_MAX);
10+
printf("The max of unsigned char is %u\n", UCHAR_MAX);
1411

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);
12+
printf("The min of signed short is %d\n", SHRT_MIN);
13+
printf("The max of signed short is %d\n", SHRT_MAX);
14+
printf("The max of unsigned short is %u\n", USHRT_MAX);
1815

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);
16+
printf("The min of signed int is %d\n", INT_MIN);
17+
printf("The max of signed int is %d\n", INT_MAX);
18+
printf("The max of unsigned int is %u\n", UINT_MAX);
2219

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-
20+
printf("The min of signed long is %ld\n", LONG_MIN);
21+
printf("The max of signed long is %ld\n", LONG_MAX);
22+
printf("The max of unsigned long is %lu\n", ULONG_MAX);
23+
24+
printf("The min of signed long long is %lld\n", LLONG_MIN);
25+
printf("The max of signed long long is %lld\n", LLONG_MAX);
26+
printf("The max of unsigned long long is %llu\n", ULLONG_MAX);
2727
}

c/bit/main.c

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

c/bubblesort/src/bubble.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ int main()
33
{
44
int a[] = {5, 10, 3, 7, 9, 6, 8, 1, 4, 2};
55
int i;
6-
int size = sizeof(a)/sizeof(a[0]);
6+
int size = sizeof(a) / sizeof(a[0]);
77
printf("Before sorting:\n");
88
for (i = 0; i < size; i++)
99
{
1010
printf("%d\n", a[i]);
1111
}
12-
bubblesort(a,size);
12+
bubblesort(a, size);
1313
printf("After sorting:\n");
1414
for (i = 0; i < size; i++)
1515
{
1616
printf("%d\n", a[i]);
1717
}
1818
return 0;
1919
}
20-
void bubblesort(int array[],int size)
20+
void bubblesort(int array[], int size)
2121
{
2222
int i, j, temp;
2323
for (i = 0; i < size; i++)

c/composition/composition.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22
#include <stdlib.h>
33
#include <string.h>
44
void write();
5-
int main(int argc,char *argv[]){
6-
//char str1[20]="114514";
7-
////char *str2 ="1919810";
8-
//char str3[]= *str2;
9-
//printf("%s\n%s\n",&str1,str2);
10-
////strcpy(str1,str3);
11-
////printf("strcpy(str1,str3):%s\n",str3)
12-
// {'b','a','k','a','\0'};
13-
if ( argc == 1 )
14-
{
15-
printf("please input name\n");
16-
//char name[] = "baka";
17-
return 0;
18-
}
5+
int main(int argc, char *argv[])
6+
{
7+
// char str1[20]="114514";
8+
////char *str2 ="1919810";
9+
// char str3[]= *str2;
10+
// printf("%s\n%s\n",&str1,str2);
11+
////strcpy(str1,str3);
12+
////printf("strcpy(str1,str3):%s\n",str3)
13+
// {'b','a','k','a','\0'};
14+
if (argc == 1)
15+
{
16+
printf("please input name\n");
17+
// char name[] = "baka";
18+
return 0;
19+
}
1920
/* else
2021
{
21-
char *name = argv[1];
22+
char *name = argv[1];
2223
}
2324
*/
24-
char composition[99];
25-
//write(composition,name);
26-
write(composition,argv[1]);
27-
printf(composition);
28-
return 0;
25+
char composition[99];
26+
// write(composition,name);
27+
write(composition, argv[1]);
28+
printf(composition);
29+
return 0;
2930
}
3031

31-
void write(char saying1[],const char *name){
32-
sprintf(saying1,"%s,my %s,I do love u so much. ",name,name);
33-
char saying2[]="Pls take me away";
34-
strcat(saying1,saying2);
32+
void write(char saying1[], const char *name)
33+
{
34+
sprintf(saying1, "%s,my %s,I do love u so much. ", name, name);
35+
char saying2[] = "Pls take me away";
36+
strcat(saying1, saying2);
3537
}

c/csqlite/main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <sqlite3.h>
4-
int main(int argc ,char* argv[]){
4+
int main(int argc, char *argv[])
5+
{
56
sqlite3 *db;
67
char zErrMsg = 0;
78
int rc;
8-
rc = sqlite3_open("test.db",&db);
9+
rc = sqlite3_open("test.db", &db);
910

10-
if (rc){
11-
fprintf(stderr, "Can't open database:%s\n",sqlite3_errmsg(db));
12-
exit(0);
13-
}else{
14-
fprintf(stderr, "Opened database successfully\n");
11+
if (rc)
12+
{
13+
fprintf(stderr, "Can't open database:%s\n", sqlite3_errmsg(db));
14+
exit(0);
15+
}
16+
else
17+
{
18+
fprintf(stderr, "Opened database successfully\n");
1519
}
1620
sqlite3_close(db);
1721
return 0;

c/fd/src/main.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "../include/fd.h"
2-
int main(){
3-
char *path="file.txt";
2+
int main()
3+
{
4+
char *path = "file.txt";
45
int fd;
5-
char buf[40],buf2[]="hello world";
6-
int n,i;
7-
if ((fd=open(path,O_RDWR))<0){
6+
char buf[40], buf2[] = "hello world";
7+
int n, i;
8+
if ((fd = open(path, O_RDWR)) < 0)
9+
{
810
perror("open file failed");
911
return 1;
1012
}
@@ -13,22 +15,25 @@ int main(){
1315
printf("open file successfully\n");
1416
}
1517

16-
if ((n=read(fd,buf,20))<0){
17-
perror("read failed");
18-
return 1;
18+
if ((n = read(fd, buf, 20)) < 0)
19+
{
20+
perror("read failed");
21+
return 1;
1922
}
2023
else
2124
{
2225
printf("output read data:\n");
23-
printf("%s\n",buf);
26+
printf("%s\n", buf);
2427
}
25-
if ((i=lseek(fd,11,SEEK_SET))<0){
28+
if ((i = lseek(fd, 11, SEEK_SET)) < 0)
29+
{
2630
perror("lseek error");
2731
return 1;
2832
}
2933
else
3034
{
31-
if (write(fd,buf2,11)<0){
35+
if (write(fd, buf2, 11) < 0)
36+
{
3237
perror("write error");
3338
return 1;
3439
}
@@ -39,23 +44,25 @@ int main(){
3944
}
4045
close(fd);
4146

42-
if ((fd=open(path,O_RDWR))<0){
47+
if ((fd = open(path, O_RDWR)) < 0)
48+
{
4349
perror("open file failed");
4450
return 1;
4551
}
4652
else
4753
{
48-
if ((n=read(fd,buf,40)<0))
54+
if ((n = read(fd, buf, 40) < 0))
4955
{
5056
perror("open file 2 failed");
5157
return 1;
5258
}
5359
else
5460
{
5561
printf("read the changed data:\n");
56-
printf("%s\n",buf);
62+
printf("%s\n", buf);
5763
}
58-
if (close(fd)<0){
64+
if (close(fd) < 0)
65+
{
5966
perror("close file failed");
6067
return 1;
6168
}

c/fileio/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../include/fileio.h"
2-
int main(){
3-
w("file.txt","this_is_an_apple");
2+
int main()
3+
{
4+
w("file.txt", "this_is_an_apple");
45
r("file.txt");
56
return 0;
67
}

c/fileio/src/r.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include "../include/fileio.h"
2-
int r(const char* filename){
3-
FILE *fp = fopen("file.txt","r");
2+
int r(const char *filename)
3+
{
4+
FILE *fp = fopen("file.txt", "r");
45
int i;
5-
long location=-2;
6-
while(ftell(fp)!=-1 && ftell(fp)!=location){
7-
//location=ftell(fp);
8-
//printf("location:%ld ",location);
6+
long location = -2;
7+
while (ftell(fp) != -1 && ftell(fp) != location)
8+
{
9+
// location=ftell(fp);
10+
// printf("location:%ld ",location);
911
char a[100];
10-
fscanf(fp,"%s",a);
11-
printf("%s \n\n",a);
12+
fscanf(fp, "%s", a);
13+
printf("%s \n\n", a);
1214
}
1315
fclose(fp);
1416
return 0;

c/fileio/src/w.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "../include/fileio.h"
2-
int w(const char* filename,const char* string){
2+
int w(const char *filename, const char *string)
3+
{
34
FILE *fp;
4-
fp = fopen(filename,"w");
5-
fprintf(fp,"%s",string);
5+
fp = fopen(filename, "w");
6+
fprintf(fp, "%s", string);
67
fclose(fp);
78
return 0;
89
}

c/fp/main.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
#include <stdio.h>
22
#include <string.h>
3-
int min(int a,int b){
4-
return a-b;
3+
int min(int a, int b)
4+
{
5+
return a - b;
56
}
6-
int mul(int a,int b){
7-
return a*b;
7+
int mul(int a, int b)
8+
{
9+
return a * b;
810
}
9-
int div(int a,int b){
10-
return a/b;
11+
int div(int a, int b)
12+
{
13+
return a / b;
1114
}
12-
int add(const char *a,const char *b){
13-
return sprintf(a,"%s%s",a,b);
15+
int add(const char *a, const char *b)
16+
{
17+
return sprintf(a, "%s%s", a, b);
1418
}
15-
int add(int a,int b){
16-
return a+b;
19+
int add(int a, int b)
20+
{
21+
return a + b;
1722
}
1823

19-
int calc(int (*fp)(int a,int b),int a , int b){
20-
return (*fp)(a,b);
24+
int calc(int (*fp)(int a, int b), int a, int b)
25+
{
26+
return (*fp)(a, b);
2127
}
2228

23-
int main(int argc,char *argv[]){
24-
int a=1,b=2;
25-
printf("%d %d=%d\n",a,b,calc(add,a,b));
29+
int main(int argc, char *argv[])
30+
{
31+
int a = 1, b = 2;
32+
printf("%d %d=%d\n", a, b, calc(add, a, b));
2633
}

0 commit comments

Comments
 (0)