首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

菜鸟重生之我要做嵌入式工程师:2-C语言【所有项目代码】

物联网 1.05MB 7 需要积分: 1
立即下载

资源介绍:

该资源包含本人初学C语言以来的所有代码,适合小白入手,主要包括: 1.环境及编译器的安装 2.基础语法的练习 3.指针的学习 4.linuxc编程的引入 5.结构体的练习
#include //头文件 #include #include #define UP 1 #define DOWN -1 #define LEFT 2 #define RIGHT -2 int key; int DIR; struct Snake { int x; int y; struct Snake* next; }; struct Food { int x; int y; }; struct Food food = {2,2}; struct Snake* snakeHead=NULL; struct Snake* snakeTail=NULL; void addNodeBehind() { struct Snake* new =(struct Snake*)malloc(sizeof(struct Snake)); new->x=snakeTail->x; new->y=(snakeTail->y)+1; new->next=NULL; snakeTail->next=new; snakeTail=new; } void snakeDie(struct Snake* snakeHead) { while(snakeHead!=NULL) { struct Snake* p =snakeHead; snakeHead=snakeHead->next; free(p); p=NULL; } } void initSnake() { snakeDie(snakeHead); snakeHead=(struct Snake*)malloc(sizeof(struct Snake)); snakeTail=(struct Snake*)malloc(sizeof(struct Snake)); snakeHead->x=1; snakeHead->y=15; snakeHead->next=NULL; snakeTail=snakeHead; addNodeBehind(); addNodeBehind(); addNodeBehind(); DIR=LEFT; } void judgeSnakeKillItself() { struct Snake* p=snakeHead->next; while(p!=NULL) { if(snakeHead->x==p->x&&snakeHead->y==p->y) { initSnake(); } else { p=p->next; } } } bool judgePos(struct Snake* snakeHead) { while(snakeHead!=NULL) { if((snakeHead->x==0||snakeHead->y==0||snakeHead->x==19||snakeHead->y==19)) { return false; } snakeHead=snakeHead->next; } return true; } void deleteHeadNode() { struct Snake* p=snakeHead; snakeHead=snakeHead->next; free(p); p=NULL; } void snakeRight() { deleteHeadNode(); addNodeBehind(); if(judgePos(snakeHead)==false) { initSnake(); } } void deleteTailNode() { struct Snake* p=snakeTail; struct Snake* headTemp=snakeHead; while(headTemp->next!=snakeTail) { headTemp=headTemp->next; } headTemp->next=NULL; snakeTail=headTemp; free(p); p=NULL; } void addNodeBefore() { struct Snake* new =(struct Snake*)malloc(sizeof(struct Snake)); switch(DIR) { case UP: new->x=snakeHead->x-1; new->y=(snakeHead->y); break; case DOWN: new->x=snakeHead->x+1; new->y=(snakeHead->y); break; case LEFT: new->x=snakeHead->x; new->y=(snakeHead->y)-1; break; case RIGHT: new->x=snakeHead->x; new->y=(snakeHead->y)+1; break; default: break; } new->next=snakeHead; snakeHead=new; } void snakeLeft() { addNodeBefore(); deleteTailNode(); if(judgePos(snakeHead)==false) { initSnake(); } } bool scanSnake(struct Snake* snakeHead,int row,int column) { int i=0; while(snakeHead!=NULL) { if(row==snakeHead->x&&column==snakeHead->y) { return true; } else { snakeHead=snakeHead->next; } } return false; } bool scanFood(struct Food food,int row,int column) { if(food.x==row&&food.y==column) { return true; } return false; } void initMyscr() { initscr();//ncruse界面的初始化函数 printw("snake\n");//在ncruse模式下的printf keypad(stdscr,1); initSnake(); } void GameMap() { int row; int column; move(1,0); for(row=0;row<20;row++) { if(row==0||row==19) { for(column=0;column<20;column++) { printw("##"); } } else { for(column=0;column<20;column++) { if(column==0) { printw("#>"); } else if(column==19) { printw("<#"); } else { if(true==scanSnake(snakeHead,row,column)) { printw("[]"); } else if(true==scanFood(food,row,column)) { printw("**"); } else { printw(" "); } } } } printw("\n"); } printw("BY ZHW\n"); } void snakeEatFood() { if(snakeHead->x==food.x&&snakeHead->y==food.y) { addNodeBehind(); struct Snake* p=snakeHead; food.x=rand()%18; food.y=rand()%18; while(p!=NULL) { while((p->x==food.x&&p->y==food.y)||food.x==0||food.y==0) { food.x=rand()%18; food.y=rand()%18; } p=p->next; } } } void* refreshMap() { while(1) { refresh(); usleep(100000); snakeLeft(); GameMap(); snakeEatFood(); judgeSnakeKillItself(); } } void posCheck(int newPos) { if(abs(DIR)!=abs(newPos)) { DIR=newPos; } } void* keyScanf() { while(1) { key=getch(); switch(key) { case KEY_UP: posCheck(UP); break; case KEY_DOWN: posCheck(DOWN); break; case KEY_LEFT: posCheck(LEFT); break; case KEY_RIGHT: posCheck(RIGHT); break; default: break; } } } int main() { initMyscr(); pthread_t p1; pthread_t P2; pthread_create(&p1,NULL,refreshMap,NULL); pthread_create(&P2,NULL,keyScanf,NULL); while(1); endwin();//程序退出,恢复终端shell,没有这句话的话终端会出现乱码。(终端会混乱) return 0; }

资源文件列表:

1-c语言.zip 大约有134个文件
  1. 1-c语言/
  2. 1-c语言/._0-hello.c 4KB
  3. 1-c语言/0-hello.c 61B
  4. 1-c语言/0-hello.exe 52.76KB
  5. 1-c语言/0-project/
  6. 1-c语言/0-project/1-snake/
  7. 1-c语言/0-project/1-snake/a.out 13.41KB
  8. 1-c语言/0-project/1-snake/snake.c 4.8KB
  9. 1-c语言/0-project/1-snake/snakeSelf.c 4.68KB
  10. 1-c语言/1-printf.c 248B
  11. 1-c语言/1-printf.exe 52.76KB
  12. 1-c语言/10-factorial.c 267B
  13. 1-c语言/10-factorial.exe 53.12KB
  14. 1-c语言/11-arryAndFun.c 403B
  15. 1-c语言/11-arryAndFun.exe 52.79KB
  16. 1-c语言/12-introPtr.c 252B
  17. 1-c语言/12-introPtr.exe 52.78KB
  18. 1-c语言/13-fun&Arrys.c 827B
  19. 1-c语言/13-fun&Arrys.exe 54.17KB
  20. 1-c语言/14-ptr.c 539B
  21. 1-c语言/14-ptr.exe 52.76KB
  22. 1-c语言/15-ptrSwap.c 245B
  23. 1-c语言/15-ptrSwap.exe 52.78KB
  24. 1-c语言/16-ptrArea.c 335B
  25. 1-c语言/16-ptrArea.exe 52.76KB
  26. 1-c语言/17-ptrArry.c 327B
  27. 1-c语言/17-ptrArry.exe 53.11KB
  28. 1-c语言/18-ptrArryReversal.c 584B
  29. 1-c语言/18-ptrArryReversal.exe 54.19KB
  30. 1-c语言/19-ptrArrys.c 540B
  31. 1-c语言/19-ptrArrys.exe 52.76KB
  32. 1-c语言/2-puts.c 128B
  33. 1-c语言/2-puts.exe 52.92KB
  34. 1-c语言/20-printfPtrArrrys.c 247B
  35. 1-c语言/20-printfPtrArrrys.exe 53.12KB
  36. 1-c语言/21-arryPtr.c 558B
  37. 1-c语言/21-arryPtr.exe 54.31KB
  38. 1-c语言/22-funPrt.c 318B
  39. 1-c语言/22-funPrt.exe 53.47KB
  40. 1-c语言/23-funPrtUse.c 569B
  41. 1-c语言/23-funPrtUse.exe 53.65KB
  42. 1-c语言/24-ptrArry.c 428B
  43. 1-c语言/24-ptrArry.exe 53.65KB
  44. 1-c语言/25-ptrArry-2.c 353B
  45. 1-c语言/25-ptrArry-2.exe 53.63KB
  46. 1-c语言/26-ptrFun.c 348B
  47. 1-c语言/26-ptrFun.exe 53.11KB
  48. 1-c语言/27-doublePtr.c 740B
  49. 1-c语言/27-doublePtr.exe 53.26KB
  50. 1-c语言/28-doublePtr-2.c 331B
  51. 1-c语言/28-doublePtr-2.exe 53.11KB
  52. 1-c语言/29-doublePtrDoubleArry.c 253B
  53. 1-c语言/29-doublePtrDoubleArry.exe 53.12KB
  54. 1-c语言/3-arry.c 280B
  55. 1-c语言/3-arry.exe 53.1KB
  56. 1-c语言/30-steCopy.c 440B
  57. 1-c语言/30-steCopy.exe 52.94KB
  58. 1-c语言/31-strNCopy.c 429B
  59. 1-c语言/31-strNCopy.exe 52.94KB
  60. 1-c语言/32-strCat.c 520B
  61. 1-c语言/32-strCat.exe 53.44KB
  62. 1-c语言/33-strCmp.c 335B
  63. 1-c语言/33-strCmp.exe 52.78KB
  64. 1-c语言/34-structEX.C 1.08KB
  65. 1-c语言/34-structEX.exe 53.94KB
  66. 1-c语言/35-structPtrArry.c 1.47KB
  67. 1-c语言/35-structPtrArry.exe 54.52KB
  68. 1-c语言/36-structPtr.c 1.8KB
  69. 1-c语言/36-structPtr.exe 54.88KB
  70. 1-c语言/37-doubleStrucPtr.c 1.8KB
  71. 1-c语言/37-doubleStrucPtr.exe 54.9KB
  72. 1-c语言/38-union.c 713B
  73. 1-c语言/38-union.exe 53.77KB
  74. 1-c语言/39-link.c 270B
  75. 1-c语言/39-link.exe 8.18KB
  76. 1-c语言/4-bubble.c 394B
  77. 1-c语言/4-bubble.exe 52.76KB
  78. 1-c语言/40-linkPrintf.c 334B
  79. 1-c语言/40-linkPrintf.exe 8.28KB
  80. 1-c语言/41-linkFind.c 497B
  81. 1-c语言/41-linkFind.exe 8.33KB
  82. 1-c语言/42-linkInsert .c 1.17KB
  83. 1-c语言/42-linkInsert.exe 54.37KB
  84. 1-c语言/43-linkDelete.c 1.11KB
  85. 1-c语言/43-linkDelete.exe 54.33KB
  86. 1-c语言/44-linkCreat.c 712B
  87. 1-c语言/44-linkCreat.exe 53.83KB
  88. 1-c语言/45-linkCreatBehind.c 971B
  89. 1-c语言/45-linkCreatBehind.exe 54.35KB
  90. 1-c语言/46-linkCreatNew.c 792B
  91. 1-c语言/46-linkCreatNew.exe 53.86KB
  92. 1-c语言/47-linkCreatBehindNew.c 914B
  93. 1-c语言/47-linkCreatBehindNew.exe 54.39KB
  94. 1-c语言/48-linkChange.c 1.3KB
  95. 1-c语言/48-linkChange.exe 54.39KB
  96. 1-c语言/49-pthread.c 515B
  97. 1-c语言/5-simpleSelection.c 389B
  98. 1-c语言/5-simpleSelection.exe 52.78KB
  99. 1-c语言/6-arrys.c 231B
  100. 1-c语言/6-arrys.exe 52.93KB
  101. 1-c语言/7-maxOfArrys.c 386B
  102. 1-c语言/7-maxOfArrys.exe 52.76KB
  103. 1-c语言/8-fun.c 262B
  104. 1-c语言/8-fun.exe 53.11KB
  105. 1-c语言/9-recursion.c 286B
  106. 1-c语言/9-recursion.exe 53.12KB
  107. 1-c语言/a.exe 53.64KB
  108. 1-c语言/homework/
  109. 1-c语言/homework/1-counter.c 242B
  110. 1-c语言/homework/1-counter.exe 53.1KB
  111. 1-c语言/homework/10-funBubble.c 716B
  112. 1-c语言/homework/10-funBubble.exe 54.31KB
  113. 1-c语言/homework/11-funSimpleSelection.c 630B
  114. 1-c语言/homework/11-funSimpleSelection.exe 54.34KB
  115. 1-c语言/homework/12-ptrSwap.c 440B
  116. 1-c语言/homework/12-ptrSwap.exe 53.79KB
  117. 1-c语言/homework/13ptrFun.c 507B
  118. 1-c语言/homework/13ptrFun.exe 52.79KB
  119. 1-c语言/homework/2-toggle case.c 240B
  120. 1-c语言/homework/2-toggle case.exe 53.1KB
  121. 1-c语言/homework/3-if.c 289B
  122. 1-c语言/homework/3-if.exe 53.1KB
  123. 1-c语言/homework/4-ifelse.c 272B
  124. 1-c语言/homework/4-ifelse.exe 53.1KB
  125. 1-c语言/homework/5-break.c 442B
  126. 1-c语言/homework/5-break.exe 53.1KB
  127. 1-c语言/homework/6-continue.c 134B
  128. 1-c语言/homework/6-continue.exe 52.76KB
  129. 1-c语言/homework/7-ex.c 551B
  130. 1-c语言/homework/7-ex.exe 53.1KB
  131. 1-c语言/homework/8-ex.c 274B
  132. 1-c语言/homework/8-ex.exe 52.76KB
  133. 1-c语言/homework/9-funEx.c 470B
  134. 1-c语言/homework/9-funEx.exe 53.15KB
0评论
提交 加载更多评论
其他资源 计算机程序设计员三级考试第三题
计算机程序设计员三级考试
计算机程序设计员三级考试第四题
计算机程序设计员三级考试
chromedriver-mac-arm64-133.0.6898.0 (1).zip
chromedriver-mac-arm64-133.0.6898.0 (1)
chromedriver-mac-arm64-133.0.6900.0.zip
chromedriver-mac-arm64-133.0.6900.0
vue2+Canvas+动态EDG数据+心电监护仪
使用vue2,利用自己封装的Canvas,实现心电监护仪的效果,数据是动态绘制,下载就可运行。
vue2+Canvas+动态EDG数据+心电监护仪 vue2+Canvas+动态EDG数据+心电监护仪 vue2+Canvas+动态EDG数据+心电监护仪
菜鸟重生之我要做嵌入式工程师:2-C51【所有项目代码】
该资源包括本人学习C51的过程中的所有代码,主要包括: 1.开发环境的搭建 2.c51单片机常用的IO口、串口、中断、定时器等 3.IIC协议、LCD1602、DHT11非标协议等 4.嵌入式常用外设(ESP8266\4G模块\语音识别模块\蓝牙模块等)
ros2-driver.zip
dddddddddaa
HC-SR04使用手册
HC-SR04超声波_原理图--.pdf HC-SR04超声波测距模块说明书--.pdf 超声波模块参考--.pdf