测试logfilec.c的时候,有个sendto(sock,msg,strlen(msg),0,&addr,addrlen),编译时提示:
logfilec.c:30: warning: passing argument 5 of ‘sendto’ from incompatible pointer type
但是书上是这样写的,在*搜了一下,原来是:
需要进行一个转换。
另外才注意到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> # ...
随机推荐
-
UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning
#import "ModelAnimationDelegate.h" #import <UIKit/UIKit.h> #import "MapVC.h&quo ...
-
【SpringMVC】SpringMVC系列7之POJO 对象绑定请求参数值
7.POJO 对象绑定请求参数值 7.1.概述 Spring MVC 会按请求参数名和 POJO 属性名进行自动匹配,自动为该对象填充属性值.而且支持级联属性.如:dept.deptId.dept ...
-
引擎设计跟踪(九.14.2e) DelayLoaded DLLs (/DELAYLOAD)
关于DLL的delay load: http://msdn.microsoft.com/en-us/library/151kt790.aspx 最近在做GLES的shader compiler, 把现 ...
-
JAVA面试题——JAVA编程题1(2015.07.22——湛耀)
实现代码很简单: package com.xiaozan.shopping; import java.util.Arrays; public class ShoppingCart { ...
-
SQL学习之汇总数据之聚集函数
一. 1.我们经常需要汇总数据而不用把他们实际检索出来,为此SQL提供了专门的函数,以便于分析数据和报表生成,这些函数的功能有: (1)确定表中行数(或者满足单个条件或多个条件或包含某个特定值的行数) ...
-
poj 3613 floyd + 快速幂
题意:本题的大意就是问从S 到 T 经过边得个数恰为k的最短路是多少. 思路:对于邻接矩阵每一次floyd求的是每个点间的最短距离,则n次floyd就是每个点间n条路的最短距离(可以重复边); 但是由 ...
-
twisted的task之cooperator和scrapy的parallel()函数
def handle_spider_output(self, result, request, response, spider): if not result: return defer_succe ...
-
Codeforces 1086D Rock-Paper-Scissors Champion
Description \(N\) 个人排成一排, 每个人都事先决定出剪刀.石头.布. 每次可以任意选两个相邻的人进行决斗. 规则和游戏一样. 但是如果平局, 则掷硬币来决定胜负. 输的人下场. 现要 ...
-
HomeBrew及HomeBrew Cask的简介和使用
前言: 最近在Mac终端上安装SVN时用到了HomeBrew工具,虽然常用,但平时没有过多了解,特翻阅了资料总结一下,以便遗忘. 目录结构: 1. 什么是HomeBrew 2. HomeBrew的主要 ...
-
[dpdk][hotplug] DPDK网卡设备热插拔
dpdk pci网卡设备的热插拔. 样例程序如下: ... ... static int driverctl(char* pci) { int pid; pid = fork(); ) { execl ...