Unix/Linux编程实践教程(三:代码、测试)
测试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编程实践教程(三:代码、测试)的更多相关文章
- 学习《Unix/Linux编程实践教程》(1):Unix 系统编程概述
0.目录 1.概念 2.系统资源 3.学习方法 4.从用户的角度来理解 Unix 4.1 登录--运行程序--注销 4.2 目录操作 4.3 文件操作 5.从系统的角度来理解 Unix 5.1 网络桥 ...
- Unix/Linux编程实践教程(0:文件、终端、信号)
本来只打算读这本书socket等相关内容,但书写得实在好,还是决定把其余的内容都读一下. 阅读联机帮助的一个示例: open系统调用: read系统调用: Unix的time: 上面的printf可以 ...
- Unix/Linux编程实践教程(二:socket、多线程、进程间通信)
同一接口不同的数据源: 协同进程: fdopen以文件描述符为参数: fopen和popen: 为了实现popen,必须在子进程中调用sh,因为只有shell本身即/bin/sh可以运行任意shell ...
- Unix/Linux编程实践教程(一:进程、管道)
execvp在程序中启动新程序: 用fork创建新进程: forkdemo2代码: 测试fork的时候参考<Linux权威指南>阅读笔记(3) 使用了patch: [root@local ...
- 学习《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 ...
- Unix Linux 编程书籍
UNIX环境高级编程(第3版) Advanced Programming in the UNIX Environment Linux/UNIX系统编程手册 Linux/UNIX系统编程手册 (豆瓣) ...
- Linux/Unix系统编程手册 第三章:系统编程概念
本章介绍系统编程的基础概念和一些后续章节用到的函数及头文件,并说明了可移植性问题. 系统调用是受控的内核入口,通过系统调用,进程可以请求内核以自己的名义去执行某些动作,比如创建子进程,执行I/O操作, ...
- UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的shell
一 分析 要实现一个shell,需包含3个步骤 1)读入指令 2)指令解析 3)执行指令 1 从键盘读入指令 从键盘读入指令的几个要点: 1)调用getc函数等待并获取用户键盘输入. 2)每一行命令的 ...
- Linux下more命令C语言实现实践 (Unix-Linux编程实践教程)
1. more第一版 实现基础功能,显示每一页固定24行文本,“q Enter”退出, “Enter” 下一行, “space Enter”下一页. #include<stdio.h> # ...
随机推荐
- Hadoop.2.x_简单的测试文件读取与上传
代码如下, 后备参考: package com.bigdata.hadoop.hdfs; import java.io.File; import java.io.FileInputStream; im ...
- Oracle--数据库中的五种约束
数据库中的五种约束 数据库中的五种约束及其添加方法 五大约束 1.--主键约束(Primay Key Coustraint) 唯一性,非空性 2.--唯一约束 (Unique Counstraint ...
- PLSQL Developer注册码
Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserial Number:601769password:xs374ca
- session.load()和session.get()的区别
Session.load/get方 法均可以根据指定的实体类和id从数据库读取记录,并返回与之对应的实体对象. 其区别在于: 如果未能发现 符合条件的记录,get方法返回null, 而load方 法会 ...
- :nth-child(an+b)
语法: :nth-child(an+b)为什么选择它,因为我认为,这个选择器是最多学问的一个了.很可惜,据我所测,目前能较好地支持她的只有Opera9+和Safari3+. 描述: 伪类:nth-ch ...
- FineUi导出时禁用ajax即EnableAjax="false"出现问题的解决方法
fineui导出时会出现乱码, 在按钮上添加EnableAjax="false"属性禁用ajax就可以正常导出.但如果我在后台代码中直接return 而不进行导出流操作,则前台脚本 ...
- IOS第12天(4,作业弹出键盘上加上(xib)view的处理,时间选择,代理模式使用,键盘的监听 )
*****HMViewController.m #import "HMViewController.h" #import "HMKeyboardTool.h" ...
- json转换对象 对象属性首字母为大写会出错 可以用以下方法
package open_exe; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; import net.sf.json.u ...
- 【ionic】Mac IOS下真机调试
模拟调试不能保证真机一定没问题,所以真机调试是非常必要的一步 IOS设备 启用设备调试 在IOS设备中(Iphone,Ipad)中开始web检测器 设备->safari->高级->w ...
- js滚动加载插件
function $xhyload(o){ var that=this; if(!o){ return; }else{ that.win=$(o.config.obj); that.qpanel=$( ...