Pending changes exported from your codespace

This commit is contained in:
outbymine 2023-05-26 08:45:03 +00:00
parent 441c308b07
commit 6673f06d6b
28 changed files with 376 additions and 0 deletions

14
Cprogramming/2dim_array.c Normal file
View file

@ -0,0 +1,14 @@
#include <stdio.h>
int main() {
//in c programming language, 2dim arrary is in row
// ini
//int a[5][3] = {{},{},{}} 分段赋值
//int a[5][3] = {} 按行连续赋值
//如果对全部元素赋值,第一维的长度可以不给出 如下
int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int b[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
return 0;
}

BIN
Cprogramming/2dim_array_pointer Executable file

Binary file not shown.

View file

@ -0,0 +1,16 @@
#include <stdio.h>
int main() {
int a[3][4] = {{0,1,2,3}, {4, 5, 6, 7}, {8, 9, 10, 11}};
int(*p)[4] = a;
//一个指向数组的指针p数组的类型为int[4]
printf("%d\n", sizeof(*(p+1))); // 16 that is because 4 * 4 = 16
/**
* *(p+1)使
* *(p+1)+1 1
* *(*(p+1)+1)
*/
return 0;
}

BIN
Cprogramming/a.out Executable file

Binary file not shown.

13
Cprogramming/array_ini.c Normal file
View file

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int a[4] = {20, 1, 2, 3}; // directly
int a[10] = {1, 2, 3, 4, 5}; //partly
int a[] = {1, 3, 4, 5, 6}; // == int a[5] = {1, 3, 4, 5, 6}
return 0;
}

BIN
Cprogramming/ball Executable file

Binary file not shown.

BIN
Cprogramming/ballGame Executable file

Binary file not shown.

96
Cprogramming/ballGame.c Normal file
View file

@ -0,0 +1,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/**
* 1. usleep函数 使
* 2. printf("\a")
* 3.
*
* https://blog.csdn.net/weixin_72939806/article/details/129221682
*/
int main() {
// 静止小球的位置
int i, j;
int x = 2; //坐标
int y = 2;
int velocity_x = 1;
int velocity_y = 1;
int left = 0;
int right = 20;
int top = 0;
int bottom = 10;
//长10 宽20
//int height = 20;
//int velocity = 1;
// printf "\033c" 清屏
// 小球下落: 让小球的x坐标增加
// 上下弹跳的小球:小球新位置 = 旧位置x + 速度velocity当判断小球到达上下边界时改变方向即改变velocity符号
// 斜着弹跳的小球增加xy两个方向的速度
while(1){
x+=velocity_x;
y+=velocity_y;
system("clear");
for(j=0;j<=right;j++) printf("_"); printf("\n");
for(i=1;i<bottom;i++){
printf("|");
for(j=0;j<right-1;j++) printf(" ");
printf("|\n");
}
for(j=0;j<=right;j++) printf("=");
printf("\033[0;0H");
for(i=0;i<x;i++)
printf("\n");
for(j=0;j<y;j++){
if(j==0)printf("|");
else printf(" ");
}
printf("o");
printf("\n");
usleep(250000);
if(x==top+1||x==bottom-1){
velocity_x=-velocity_x;
printf("\a");
}
if(y==left+1||y==right-1){
velocity_y=-velocity_y;
printf("\a");
}
}
// for(x=1; x < 10; x++) {
// system("clear");
// for (i=0; i < x; i++) {
// printf("\n");
// }
// for (j = 0; j < y; j++) {
// printf(" ");
// }
// printf("o");
// printf("\n");
// //sleep(1);
// usleep(200000); // 500毫秒 * 1000 微秒/毫秒 = 500000 微秒
// }
return 0;
}

15
Cprogramming/char_array.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
//字符数组实际上就是一系列字符的集合也就是字符串
char str[30] = {"asdasdasdasdasdasd"};
char str[20] = "asdasdasasfs";
char str[] = "fefegfef";
//字符数组只有在定义的时候可以一整个字符串一次性赋值给他,一旦定义完了,就只能一个字符一个字符地赋值了
return 0;
}

BIN
Cprogramming/end_of_string Executable file

Binary file not shown.

View file

@ -0,0 +1,17 @@
#include <stdio.h>
//局部变量的初始值不一定全是0
int main() {
char str[30];
char c;
int i;
for (c = 65, i = 0; c <= 90; c++, i++) {
str[i] = c;
}
str[i] = 0; //也可以写作str[i] = '\0'手动结束字符串
//更专业的做法是 将str初始就全为0 str = {0};
printf("%s\n", str);
return 0;
}

BIN
Cprogramming/func_pointer Executable file

Binary file not shown.

View file

@ -0,0 +1,20 @@
#include <stdio.h>
int max(int a, int b) {
return a>b ? a : b;
}
int main() {
int x, y, maxval;
int (*pmax)(int, int) = max;
//函数指针
printf("input two numbers:");
scanf("%d %d", &x, &y);
maxval = (*pmax)(x,y);
printf("Max value: %d\n", maxval);
return 0;
}

10
Cprogramming/gets_scanf.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
int main() {
//gets 可以接受带空格的字符串
//scanf 不行,but 不是完全不行
return 0;
}

View file

@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
printf("Hello world");
return 0;
}

View file

@ -0,0 +1,19 @@
#include <stdio.h>
int main() {
/**
* int *p1[6];
* int *(p2[6]);
* int (*p3)[6];
* int (*p4)(int, int);
*
*/
//c语言标准规定对于一个符号的定义编译器总是从**它的名字**开始读,然后按照优先级顺序依次解析
//优先级顺序: 定义中被括号()扩起的,
// 后缀操作:()表示这是一个函数,[] 表示这是一个数组
// 前缀操作: * 表示指向xxx的指针
return 0;
}

BIN
Cprogramming/main_advanced Executable file

Binary file not shown.

View file

@ -0,0 +1,14 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
//argc表示传递的字符串的数目argv是一个指针数组每一个指针指向一个字符串
int i;
printf("The program receives %d parameters:\n", argc);
for (i=0; i<argc; i++) {
printf("%s\n", argv[i]);
}
return 0;
}

View file

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <stdio.h>
int main() {
while(1) {
malloc(1024); // allocate 1024bytes
}
return 0;
}

BIN
Cprogramming/non-blockingListen Executable file

Binary file not shown.

View file

BIN
Cprogramming/passw Executable file

Binary file not shown.

48
Cprogramming/passw.c Normal file
View file

@ -0,0 +1,48 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define PWDLEN 20
void getpwd(char *pwd, int pwdlen);
int main()
{
char pwd[PWDLEN + 1];
printf("Input password: ");
getpwd(pwd, PWDLEN);
system("stty echo");
printf("The password is: %s\n", pwd);
return 0;
}
/**
* get the password by users
* @param pwd char*
* @param pwdlen int
*/
void getpwd(char *pwd, int pwdlen) {
char ch = 0;
int i = 0;
system("stty -echo");//取消回显
while (i < pwdlen) { //循环输入密码
ch = getchar();
if (ch == '\n') { //unix敲入回车结束
//printf("\n");
break;
}
if (ch == '\b' && i > 0) {//删除键回退之后覆盖
i--;
//printf("\b \b");
} else if (isprint(ch)) {
pwd[i] = ch;
//printf("*");
i++;
}
}
pwd[i] = 0; //最后结束
printf("\n");
//system("stty echo");
}

29
Cprogramming/pointer.c Normal file
View file

@ -0,0 +1,29 @@
/**
* Notes on Pointer Full
* 1.
* datatype *name
*
* 2.*&
* int a pa是指向它的指针
* 2.1 *&a是什么意思
* attempt*&a == a
* 2.2 &*pa是什么意思
* attempt == pa
*
* 3.
* 3.1 *p++ = *p++
* 3.2 *++p = *++p
*
*
* 4.
*
*/
#include <stdio.h>
int main() {
return 0;
}

BIN
Cprogramming/problem_pointer Executable file

Binary file not shown.

View file

@ -0,0 +1,46 @@
#include <stdio.h>
int main() {
char *lines[5]= {
"COSC1283/1284",
"Programming",
"Techniques",
"is",
"great fun"
};
/**
* :
* char *string0 = "C0SC1283/1284"
* char *string1 = "Programming"
* char *string2 = "Techniques"
* char *string3 = "is"
* char *string4 = "great fun"
*
* char *lines[5];
* lines[0] = string0;
* lines[1] = string1;
* ....
*
*  char* lines[5]
*/
char *str1 = lines[1];
//attempt: str1存放着"COSC1283/1284"的首地址
char *str2 = *(lines + 3);
//att: str2存放着“is”的首地址
char c1 = *(*(lines + 4) + 6);
//att: c1 = 'f'
char c2 = (*lines + 5)[5];
//att: c2 =
char c3 = *lines[0] + 2;
//att: c3 = 'C'
printf("str1 = %s\n", str1);
printf("str2 = %s\n", str2);
printf(" c1=%c\n",c1);
printf(" c2=%c\n",c2);
printf(" c3=%c\n",c3);
return 0;
}

View file

1
conio.h Submodule

@ -0,0 +1 @@
Subproject commit 70935b61efce6da9042f3543add106e7dc52e3ca