当前位置: 首页 > wzjs >正文

如何做国外的社交网站广西网站建设费用

如何做国外的社交网站,广西网站建设费用,网络运营推广平台,慈溪市规划建设网站在Linux上编译Ncurses程序的教程 简介 Ncurses(New Curses)是一个用于创建文本用户界面(TUI)的库,广泛用于Unix-like系统中。它提供了丰富的函数来处理屏幕输出、键盘输入、光标控制等。本文将指导您如何在Linux环境…

在Linux上编译Ncurses程序的教程

简介

Ncurses(New Curses)是一个用于创建文本用户界面(TUI)的库,广泛用于Unix-like系统中。它提供了丰富的函数来处理屏幕输出、键盘输入、光标控制等。本文将指导您如何在Linux环境下编译和运行一个简单的Ncurses程序。

ncurses函数使用介绍:

  • initscr():初始化屏幕,进入curses模式。这是使用ncurses库时首先要调用的函数。

  • keypad():启用或禁用特殊按键的读取。当设置为 TRUE 时,可以读取如方向键、功能键等特殊按键。

  • noecho():关闭按键回显,即用户输入的字符不会显示在屏幕上。

  • printw():在当前光标位置打印文本。

  • refresh():将缓冲区的内容刷新到屏幕上,使更改立即可见。

  • getch():等待用户按键并返回按键的ASCII值。如果按下的是特殊按键(如方向键),则返回相应的宏定义值。

  • endwin():结束curses模式,恢复终端到调用 initscr() 之前的状态。

  • clear():清除屏幕,将所有内容重置为空白。

  • move(y, x):移动光标到指定的行 y 和列 x 位置。

环境准备

确保您的Linux系统已经安装了GCC编译器和Ncurses库。如果没有安装,可以通过以下命令安装:

bash复制

sudo apt update
sudo apt install build-essential libncurses5-dev libncursesw5-dev

创建Ncurses程序

  1. 创建源文件:创建一个名为 hello_ncurse.c 的文件,并输入以下代码:

    c复制

    #include <ncurses.h>int main() {int ch;initscr();                      // Start curses modeprintw("Hello World !!!");      // Print Hello Worldrefresh();                      // Print it on to the real screench = getch();                   // Wait for user inputendwin();                       // End curses modereturn 0;
    }
  2. 编译程序:使用以下命令编译您的程序:

    bash复制

    gcc -o hello_ncurse hello_ncurse.c -lncurses

    这里,gcc 是GNU编译器集合,-o hello_ncurse 指定输出文件名,hello_ncurse.c 是源文件,-lncurses 链接Ncurses库。

  3. 运行程序:编译成功后,运行编译后的程序:

    bash复制

    ./hello_ncurse

    您应该能看到屏幕上显示 "Hello World !!!"。

实现一个简单的Ncurses游戏

为了进一步演示Ncurses的功能,我们将创建一个简单的游戏,其中字符 "O" 会在屏幕上左右移动。

  1. 创建源文件:创建一个名为 move字符.c 的文件,并输入以下代码:

    #include <ncurses.h>int main() {int key, x, y;initscr();                      // Initialize the ncurses librarykeypad(stdscr, TRUE);          // Enable special keys like arrow keys to be read directlynoecho();                       // Disable echoing of key presses to the screenx = y = 5;                      // Initialize the x and y coordinates for the objectwhile (key != 'q') {            // Main game loop, continues until 'q' is pressedclear();                    // Clear the screenmove(0, 0);                 // Put the cursor at the start of the screenprintw("Press left or right arrow - exit by pressing:q"); // Print instructions on the screenmove(y, x);                 // Move the cursor to the current position of the objectprintw(" OOOO ");            // Print the object at the current positionrefresh();                  // Refresh the screen to show the changeskey = getch();              // Wait for a key pressif (key == KEY_LEFT) {      // If the left arrow key is pressedx--;                    // Move the object leftif (x < 0) x = 0;      // Ensure the object does not move out of the left boundary} else if (key == KEY_RIGHT) { // If the right arrow key is pressedx++;                    // Move the object rightif (x > 30) x = 30;    // Ensure the object does not move out of the right boundary}}endwin();                       // End the ncurses mode and restore the terminal to its original statereturn 0;
    }
  2. 编译程序:使用以下命令编译你的程序:

    bash复制

    gcc -o move_char move_char.c -lncurses
  3. 运行程序:编译成功后,运行编译后的程序:

    bash复制

    ./move_char

    你应该能看到字符 "O" 在屏幕上左右移动。

如果不知道如何在linux文件运行,请回看我之前发的samba和makefile文章

最后结果是这样的


文章转载自:

http://dM9wb4d8.sftrt.cn
http://OEMltrDl.sftrt.cn
http://OPNbII2P.sftrt.cn
http://VQkmRf0v.sftrt.cn
http://0jn7ZERF.sftrt.cn
http://fWrOmNlt.sftrt.cn
http://cn0jdQmR.sftrt.cn
http://59LIsP6m.sftrt.cn
http://NXU3f32P.sftrt.cn
http://Meyy9lqN.sftrt.cn
http://MYHVtVRC.sftrt.cn
http://4MuRtdCm.sftrt.cn
http://5x4ZJom1.sftrt.cn
http://Z3of3Mss.sftrt.cn
http://YSWN3ZhP.sftrt.cn
http://4T2YpBMs.sftrt.cn
http://C4p4C889.sftrt.cn
http://FWrzHUHW.sftrt.cn
http://L341TfP6.sftrt.cn
http://PpjnT2Er.sftrt.cn
http://JXzO0FDj.sftrt.cn
http://CycqTlOS.sftrt.cn
http://PkIrWWeJ.sftrt.cn
http://C3XBz6Jh.sftrt.cn
http://ob9qriip.sftrt.cn
http://wF8wdFOS.sftrt.cn
http://GR450uQd.sftrt.cn
http://lb07EGwj.sftrt.cn
http://MfMxv9IC.sftrt.cn
http://HGNf9JfA.sftrt.cn
http://www.dtcms.com/wzjs/721125.html

相关文章:

  • 做网站收入怎么样做什么网站
  • 济南智能网站建设哪家好厦门网站开发排名
  • 传媒公司做网站条件什么是cms系统
  • 深圳网站开发深圳网站设计站长工具查询域名
  • 怎么建立购物网站电脑h5制作工具
  • 哈尔滨做网站数据平台的公司wordpress 望远镜销售
  • 金融投资网站开发wordpress高速优化
  • 江门网站建设推广平台免费咨询的律师有吗
  • 福建省城乡建设信息网站wordpress百度seo优化插件
  • 建设银行大丰支行网站小程序公司
  • 网站模版购买发布找个网站看看
  • 网站怎么做才美观推广游戏网站怎么做
  • 网站开发相关知识全国室内设计学校
  • 网站不备案会怎...网站建设推广的话术
  • 二手网站怎么做律师网站建设推荐
  • php网站开发工资多少h5商城网站建设是什么
  • 门户网站关键词知名电商平台有哪些
  • 网站网页设计公司在阿里巴巴上做网站要多少钱
  • 把做的网站放到互联网上营销网页设计
  • 网站优化入门免费教程番禺移动网站建设
  • 东莞企业网站设计inews wordpress
  • 网站系统建设招标文件wordpress 新建用户
  • 做网站的怎么找客户国外网站网站app
  • 关于网站开发人员的薪资网站设计软件免费下载
  • 在哪个网站找装修公司充值选建设银行打不开网站
  • 南京建站平台yy直播官网
  • 站长统计ios揭阳网站制作专业
  • 阿里云网站实名认证怎样提高网站速度
  • 云服务器上放多个网站制作手机app开发
  • 广州外贸网站咨询缠绕机东莞网站建设技术支持