Github上 https://github.com/TheAlgorithms/C
The repository is a collection of open-source implementations of a variety of algorithms implemented in C and licensed under GPLv3 License. The algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and their associated documentations are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using different algorithm strategies and optimizations.

ncurses

使用 ncurses 在 Linux 终端屏幕上的特定位置放置文本,可以带来更友好的用户界面体验。
https://invisible-island.net/ncurses/announce.html

ascii-rain

Comfy rain for your console written in C with Ncurses.
C项目 - 图1
Dependencies
You’ll need a ncurses library. For Ubuntu packages are: ‘ncurses-dev’ or ‘libncurses-dev’. For OSX try $ brew install ncurses.

井字棋游戏


  1. #include <stdio.h>
  2. #include <conio.h>
  3. char square[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  4. int checkwin();
  5. void board();
  6. int main()
  7. {
  8. int player = 1, i, choice;
  9. char mark;
  10. do
  11. {
  12. board();
  13. player = (player % 2) ? 1 : 2;
  14. printf("Player %d, enter a number: ", player);
  15. scanf("%d", &choice);
  16. mark = (player == 1) ? 'X' : 'O';
  17. if (choice == 1 && square[1] == '1')
  18. square[1] = mark;
  19. else if (choice == 2 && square[2] == '2')
  20. square[2] = mark;
  21. else if (choice == 3 && square[3] == '3')
  22. square[3] = mark;
  23. else if (choice == 4 && square[4] == '4')
  24. square[4] = mark;
  25. else if (choice == 5 && square[5] == '5')
  26. square[5] = mark;
  27. else if (choice == 6 && square[6] == '6')
  28. square[6] = mark;
  29. else if (choice == 7 && square[7] == '7')
  30. square[7] = mark;
  31. else if (choice == 8 && square[8] == '8')
  32. square[8] = mark;
  33. else if (choice == 9 && square[9] == '9')
  34. square[9] = mark;
  35. else
  36. {
  37. printf("Invalid move ");
  38. player--;
  39. getch();
  40. }
  41. i = checkwin();
  42. player++;
  43. }while (i == - 1);
  44. board();
  45. if (i == 1)
  46. printf("==>\aPlayer %d win ", --player);
  47. else
  48. printf("==>\aGame draw");
  49. getch();
  50. return 0;
  51. }
  52. /*********************************************
  53. FUNCTION TO RETURN GAME STATUS
  54. 1 FOR GAME IS OVER WITH RESULT
  55. -1 FOR GAME IS IN PROGRESS
  56. O GAME IS OVER AND NO RESULT
  57. **********************************************/
  58. int checkwin()
  59. {
  60. if (square[1] == square[2] && square[2] == square[3])
  61. return 1;
  62. else if (square[4] == square[5] && square[5] == square[6])
  63. return 1;
  64. else if (square[7] == square[8] && square[8] == square[9])
  65. return 1;
  66. else if (square[1] == square[4] && square[4] == square[7])
  67. return 1;
  68. else if (square[2] == square[5] && square[5] == square[8])
  69. return 1;
  70. else if (square[3] == square[6] && square[6] == square[9])
  71. return 1;
  72. else if (square[1] == square[5] && square[5] == square[9])
  73. return 1;
  74. else if (square[3] == square[5] && square[5] == square[7])
  75. return 1;
  76. else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
  77. square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7]
  78. != '7' && square[8] != '8' && square[9] != '9')
  79. return 0;
  80. else
  81. return - 1;
  82. }
  83. /*******************************************************************
  84. FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
  85. ********************************************************************/
  86. void board()
  87. {
  88. system("cls");
  89. printf("\n\n\tTic Tac Toe\n\n");
  90. printf("Player 1 (X) - Player 2 (O)\n\n\n");
  91. printf(" | | \n");
  92. printf(" %c | %c | %c \n", square[1], square[2], square[3]);
  93. printf("_____|_____|_____\n");
  94. printf(" | | \n");
  95. printf(" %c | %c | %c \n", square[4], square[5], square[6]);
  96. printf("_____|_____|_____\n");
  97. printf(" | | \n");
  98. printf(" %c | %c | %c \n", square[7], square[8], square[9]);
  99. printf(" | | \n\n");
  100. }
  101. /*******************************************************************
  102. END OF PROJECT
  103. ********************************************************************/