learn and do
haoshuang3394 · 共 146 篇文章
从标准输入读命令并执行
#include "apue.h" #include <sys/wait.h> int main(void) { char buf[MAXLINE];//from apue.h pid_t pid; int status; printf("%% ");//print prompt while(fgets(buf,MAXLINE,stdin)!=NULL){ if(buf[strlen(buf)-1]=='\n') buf[strlen(buf)-1]=0;//replace newline with null if((pid=fork())<0){ err_sys("fork error")…
2009-07-05 17:48 · unix环境高级编程 · 评论(0) · C · C++ · C#
getpid() 函数
#include "apue.h" int main(void) { printf("hello world from process ID %d\n",getpid()); exit(0); } 编译: gcc -o pid pid.c 运行: ./pid 得结果: hello world from process ID 6367 说明: 第一次运行时,此数字(6367)可能在不同的机器上都不同。 第二次运行时,得结果 hello world from process ID 6383 数字越来越大。 调用函数getpid时,得到程序pid的进程ID。
2009-07-04 13:31 · unix环境高级编程 · 评论(0) · C · C++ · GCC · C#
在ubuntu8.10下qt开发环境搭建
我的操作系统是ubuntu8.10,可以在网上找到安装qt编译环境的安装方法。现简略叙述如下: (1)sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos qt4-designer 此命令安装了五个软件。 qt4-dev-tools是qt开发的一些工具包,此命令的作用即将qt4的一些头文件和库文件下载,然后解压,最后将解压出来的头文件复制到/usr/include目录,将解压出来的库文件复制到/usr/lib目录,使开发者在编写qt程序的时候,可以如调用标准C++头文件一样调用qt的头文件。 qt4-doc是一个帮…
2009-07-03 12:46 · qt学习 · 评论(0) · C · C++ · Qt · C# · IDE
getc()函数和putc()函数的用法
#include "apue.h" int main(void) { int c; while((c=getc(stdin))!=EOF) if(putc(c,stdout)==EOF) err_sys("output error!"); if(ferror(stdin)) err_sys("input error!"); exit(0); } 我将上面这个程序命名为getchar.c。 编译: gcc -o getchar getchar.c 运行: ./getchar 程序讲解: 函数getc一次读入一个字符,然后函数putc将此字符写到标准输出。读到输入的最后一个字符时,getc返回常…
2009-07-03 12:17 · unix环境高级编程 · 评论(0) · C · C++ · GCC · C#
将标准输入复制到标准输出
#include "apue.h" #define BUFFSIZE 4096 int main(void) { int n; char buf[BUFFSIZE]; while((n=read(STDIN_FILENO,buf,BUFFSIZE))>0) if(write(STDOUT_FILENO,buf,n)!=n) err_sys("write error!"); if(n<0) err_sys("read error!"); exit(0); } 我将上面这段代码命名为in2out.c,编译: gcc -o in2out in2out.c 将此程序的目标文件命名为in2out。 运…
2009-07-02 16:49 · unix环境高级编程 · 评论(0) · C · C++ · GCC · C#
在ubuntu8.10下搞定《unix环境高级编程》第一个例子
本人的所用操作系统是ubuntu8.10。 开始学习《unix环境高级编程》,编译第一个例子就出现了问题: myls.c:1:19: apue.h: No such file or directory myls.c: In function `main': myls.c:13: error: `NULL' undeclared (first use in this function) myls.c:13: error: (Each undeclared identifier is reported only once myls.c:13: error: for each function i…
2009-07-01 14:50 · unix环境高级编程 · 评论(0) · C · C++ · Unix · C# · 编程
ARM和Linux学习方法指导
ARM的学习。有了单片机或计算机结构的基本知识、c语言的基础,上手ARM是比较容易的。学习ARM,首先应当 了解一下ARM的体系结构,了解它有哪些版本、哪些模式、哪些寄存器、异常等。这方面的内容可以参考《ARM体系结构与编程》一书,这本书介绍的内容比较全,可以先快速浏览,特别是一些汇编指令不需要记住,以后开发时可以参考相关的手册。其次选定一种具体厂家型号的ARM处理器,学习该处理器相关的开发工具的使用,如开发环境、仿真器及评估板等。然后可以分析该处理器的外围扩展方法,如SDRAM、NAND Flash等,一般官方或第三方都会提供原理图,可以用来分析。接下来要理解该处理器的启动过程,亲自尝试从…
2009-06-28 16:24 · 嵌入式开发 · 评论(0) · 网络应用 · 浏览器 · 编程 · 嵌入式 · Linux
Stroking or Filling with a Gradient Color
Color startColor = Color.red; Color endColor = Color.blue; // A non-cyclic gradient GradientPaint gradient = new GradientPaint( startX, startY, startColor, endX, endY, endColor); g2d.setPaint(gradient); drawShape(g2d); // A cyclic gradient gradient = new GradientPaint( startX, startY, startColor, e…
2009-06-22 23:56 · java学习 · 评论(0)
文字常量(2)
一般的转义序列采用如下格式 \ooo 这里的ooo 代表三个八进制数字组成的序列,八进制序列的值代表该字符在机器字符集 里的数字值。下面的示例使用ASCII 码字符集表示文字常量 \7 (bell) \14 (newline) \0 (null) \062 ('2') 另外字符文字前面可以加L,例如 L'a' 这称为宽字符文字类型为wchar_t,宽字符常量用来支持某些语言的字符集合。如汉语、 日语这些语言中的某些字符不能用单个字符来表示。 字符串文字常量由零个或多个用双引号括起来的字符组成,不可打印字符可以由相应的 转义序列来表示,而一个字符串文字可以扩展到多行,在一行的最后加上一个反斜杠…
2009-06-22 23:41 · C++学习 · 评论(0) · C · C++ · C#
Scoping.py源代码分析
x = 1 # global variable #全局变量 # alters the local variable x, shadows the global variable def a(): x = 25 #局部变量 print "\nlocal x in a is", x, "after entering a" #打印局部变量 x += 1 print "local x in a is", x, "before exiting a" #打印变化后的局部变量 # alters the global variable x def b(): global x #声明使用全局变量x print…
2009-06-22 23:25 · python学习 · 评论(0)
seekjob_info.php源代码分析
<link href="css/style.css" rel="stylesheet"> <?php include("conn/conn.php"); %数据库连接文件 ?> <table width="563" height="587" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="563" height="587" valign="top" bgcolor="#FFFFFF"><table width="563" border="0" cellspacing="0" cellpadding="0"> <tr> <…
2009-06-22 23:13 · php学习 · 评论(0) · CSS · PHP · SQL · MySQL
Stroking or Filling with a Color:画或填充一种颜色
// Use a predefined color. g2d.setColor(Color.red); drawShape(g2d); // Use a custom color. int red = 230; int green = 45; int blue = 67; g2d.setColor(new Color(red, green, blue)); drawShape(g2d);
2009-06-21 23:43 · java学习 · 评论(0)
文字常量(1)
C++预定义了一组数值数据类型,可以用来表示整数、浮点数和单个字符。此外,还预 定义了用来表示字符串的字符数组。 字符型char 通常用来表示单个字符和小整数,它可以用一个机器字节来表示。 整型int、短整型short、长整型long它们分别代表不同长度的整数值。典型情况 下short 以半个字表示,int 以一个机器字表示,而long 为一个或两个机器字。在 32 位机器中int 和long 通常长度相同。 浮点型float、双精度double和长双精度long double分别表示单精度浮点数、双 精度浮点数和扩展精度的浮点数值。典型情况下float 为一个字,double 是两个字, …
2009-06-21 23:43 · C++学习 · 评论(0) · F#
frequency.py源代码分析
import random #导入random包 frequency1 = 0 frequency2 = 0 frequency3 = 0 frequency4 = 0 frequency5 = 0 frequency6 = 0 #定义六个变量,分别计频数 for roll in range( 1, 6001 ): # 6000 die rolls face = random.randrange( 1, 7 ) #掷6000次 if face == 1: # frequency counted frequency1 += 1 elif face == 2: frequency2 += 1 e…
2009-06-21 21:47 · python学习 · 评论(0)
seekjob.php源代码分析
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <link href="css/style.css" rel="stylesheet"> <title>九九供求信息网</title> <style type="text/css"> <!-- body { background-image: url(Images/bg.gif); } --> </style> </head> <body> <table width="780" border="0" align="center"…
2009-06-21 21:46 · php学习 · 评论(0) · HTML · CSS · PHP