测试logfilec.c的时候,有个sendto(sock,msg,strlen(msg),0,&addr,addrlen),编译时提示:

logfilec.c:30: warning: passing argument 5 of ‘sendto’ from incompatible pointer type

但是书上是这样写的,在stackoverflow搜了一下,原来是:

需要进行一个转换。

另外才注意到C语言中单引号可转义可不转。

需要用curses库的测试hello1.c,发现没有,需要安装。

//hello1.c
#include<stdio.h>
#include<curses.h>
#include<stdlib.h> main()
{
initscr(); clear();
move(,);
addstr("hello,world");
move(LINES-,);
refresh();
getch();
endwin();
}

hello1.c

按照yum的安装,安装失败,yum命令无法成功运行。还是不能成功编译hello1.c。

后来网上看才发现CentOS已经默认安装curses,只是编译时需链接库:

gcc hello1.c -o hello1 -lcurses

测试bounce1d.c时,提示:

undefined reference to `set_ticker'

原来set_ticker这个函数并不包含在库里面,需要自己编写。

//bounce1d.c
#include<stdio.h>
#include<curses.h>
#include<sys/time.h>
#include<signal.h>
#include<string.h> #define MESSAGE "hello"
#define BLANK " " int row;
int col;
int dir; int main()
{
int delay;
int ndelay;
int c;
void move_msg(int);
int set_ticker(long);
initscr();
crmode();
noecho();
clear(); row=;
col=;
dir=;
delay=; move(row,col);
addstr(MESSAGE);
signal(SIGALRM,move_msg);
set_ticker(delay); while()
{
ndelay=;
c=getch();
if(c=='q') break;
if(c==' ') dir=-dir;
if(c=='f'&&delay>) ndelay=delay/;
if(c=='s') ndelay=delay*;
if(ndelay>)
set_ticker(delay=ndelay);
} endwin();
return ; } void move_msg(int signum)
{
signal(SIGALRM,move_msg);
move(row,col);
addstr(BLANK);
col+=dir;
move(row,col);
addstr( MESSAGE);
refresh(); if(dir==-&&col<=)
dir=;
else if(dir==&&col+strlen(MESSAGE)>=COLS)
dir=-;
} int set_ticker(long n_msecs)
{
struct itimerval new_timeset;
long n_sec,n_usecs; n_sec=n_msecs/;
n_usecs=(n_msecs%)*1000L; new_timeset.it_interval.tv_sec=n_sec;
new_timeset.it_interval.tv_usec=n_usecs;
new_timeset.it_value.tv_sec=n_sec;
new_timeset.it_value.tv_usec=n_usecs; return setitimer(ITIMER_REAL,&new_timeset,NULL); }

bounce1d.c

Unix/Linux编程实践教程(三:代码、测试)的更多相关文章

  1. 学习《Unix/Linux编程实践教程》(1):Unix 系统编程概述

    0.目录 1.概念 2.系统资源 3.学习方法 4.从用户的角度来理解 Unix 4.1 登录--运行程序--注销 4.2 目录操作 4.3 文件操作 5.从系统的角度来理解 Unix 5.1 网络桥 ...

  2. Unix/Linux编程实践教程(0:文件、终端、信号)

    本来只打算读这本书socket等相关内容,但书写得实在好,还是决定把其余的内容都读一下. 阅读联机帮助的一个示例: open系统调用: read系统调用: Unix的time: 上面的printf可以 ...

  3. Unix/Linux编程实践教程(二:socket、多线程、进程间通信)

    同一接口不同的数据源: 协同进程: fdopen以文件描述符为参数: fopen和popen: 为了实现popen,必须在子进程中调用sh,因为只有shell本身即/bin/sh可以运行任意shell ...

  4. Unix/Linux编程实践教程(一:进程、管道)

    execvp在程序中启动新程序: 用fork创建新进程: forkdemo2代码: 测试fork的时候参考<Linux权威指南>阅读笔记(3)  使用了patch: [root@local ...

  5. 学习《Unix/Linux编程实践教程》(2):实现 more

    0.目录 1.more 能做什么? 2.more 是如何实现的? 3.实现 more 3.1 more01.c 3.2 more02.c 3.3 more03.c 1.more 能做什么? more ...

  6. Unix Linux 编程书籍

    UNIX环境高级编程(第3版) Advanced Programming in the UNIX Environment Linux/UNIX系统编程手册 Linux/UNIX系统编程手册 (豆瓣) ...

  7. Linux/Unix系统编程手册 第三章:系统编程概念

    本章介绍系统编程的基础概念和一些后续章节用到的函数及头文件,并说明了可移植性问题. 系统调用是受控的内核入口,通过系统调用,进程可以请求内核以自己的名义去执行某些动作,比如创建子进程,执行I/O操作, ...

  8. UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的shell

    一 分析 要实现一个shell,需包含3个步骤 1)读入指令 2)指令解析 3)执行指令 1 从键盘读入指令 从键盘读入指令的几个要点: 1)调用getc函数等待并获取用户键盘输入. 2)每一行命令的 ...

  9. Linux下more命令C语言实现实践 (Unix-Linux编程实践教程)

    1. more第一版 实现基础功能,显示每一页固定24行文本,“q Enter”退出, “Enter” 下一行, “space Enter”下一页. #include<stdio.h> # ...

随机推荐

  1. Button,CheckBox,Lable,RadioButton,ComboBox,TextBox六个简单控件的使用

    所有文字的更改全部在Text属性中更改! ComboBox:点击右上方小箭头,选择编辑项弹出: RadioButton:,Checked属性选择True,表示已被选中: Button:在设计中双击按钮 ...

  2. Linux_安装软件包

    一.软件包: 源码包 二进制包(rpm包,编译完成) 依赖性 包A-->包B-->包C 一.rpm 挂载镜像,从镜像文件中找到要安装的rpm包 [root@hadoop09-linux ~ ...

  3. Java获取前天和后天的时间

    import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import j ...

  4. Git分布式项目管理

          Git简介 Git是什么? Git和SVN一样都是一种高效的管理代码的系统. Git是目前世界上最先进的分布式版本控制系统(没有之一). 创建版本库 什么是版本库呢?版本库又名仓库,英文名 ...

  5. 【iCore3 双核心板_FPGA】实验十五:基于USART的ARM与FPGA通信实验

    实验指导书及代码包下载: http://pan.baidu.com/s/1c1RbE5E iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  6. 为什么Visual Studio的安装目录下有名为1033或2052的文件夹?

    一直不清楚MS诸多产品的安装目录下为什么总有个名为1033或者2052的目录 搜索一下才知道,原来叫 LCID(Locale ID,区域性标识符) 常见的如:1033表示英语(美国),2052表示中文 ...

  7. iostat监控磁盘io

    1.安装#yum install sysstat 2.启动#/etc/init.d/sysstat start 3.自启动#checkfig sysstat 4.基本使用#iostat -k 2每两秒 ...

  8. 《Linux内核分析》第四周 扒开系统调用的“三层皮”

    [刘蔚然 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] WEEK FOUR( ...

  9. 简单实用的双向电平转换电路(3.3v-5v)

    当你使用3.3V的单片机的时候,电平转换就在所难免了,经常会遇到3.3转5V或者5V转3.3V的情况,这里介绍一个简单的电路,他可以实现两个电平的相互转换(注意是相互哦,双向的,不是单向的!).电路十 ...

  10. Mybatis 与 spring mvc

    本文是用来小结一下自己mybatis 和spring mvc 学习过程. 在写的过程中发现 http://www.phperz.com/article/15/0127/48684.html 这篇文章里 ...