随笔 - 20, 文章 - 0, 评论 - 5, 引用 - 0
数据加载中……

2010年12月27日

fwrite

size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );

Write block of data to stream

Writes an array of count elements, each one with a size of size bytes, from the block of memory pointed by ptr to the current position in the stream.
The postion indicator of the stream is advanced by the total number of bytes written.
The total amount of bytes written is (size * count).

Parameters

ptr
Pointer to the array of elements to be written.
size
Size in bytes of each element to be written.
count
Number of elements, each one with a size of size bytes.
stream
Pointer to a FILE object that specifies an output stream.


Return Value

The total number of elements successfully written is returned as a size_t object, which is an integral data type.
If this number differs from the count parameter, it indicates an error.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* fwrite example : write buffer */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  char buffer[] = { 'x' , 'y' , 'z' };
  pFile = fopen ( "myfile.bin" , "wb" );
  fwrite (buffer , 1 , sizeof(buffer) , pFile );
  fclose (pFile);
  return 0;
}


A file called myfile.bin is created and the content of the buffer is stored into it. For simplicity, the buffer contains char elements but it can contain any other type.
sizeof(buffer) is the length of the array in bytes (in this case it is three, because the array has three elements of one byte each).

posted @ 2010-12-27 13:53 Eping 阅读(424) | 评论 (0)编辑 收藏

fprintf

int fprintf ( FILE * stream, const char * format, ... );

Write formatted output to stream

Writes to the specified stream a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format.

Parameters

stream
Pointer to a FILE object that identifies the stream.
format
C string that contains the text to be written to the stream.
It can optionally contain embedded format tags that are replaced by the values specified in subsequent additional arguments and formatted as requested.
The number of arguments following the format parameters should at least be as much as the number of format tags.
The format tags follow this prototype:

%[flags][width][.precision][length]specifier

Where specifier is the most significant one and defines the type and the interpretation of the value of the coresponding argument:
specifierOutputExample
cCharactera
d or iSigned decimal integer392
eScientific notation (mantise/exponent) using e character3.9265e+2
EScientific notation (mantise/exponent) using E character3.9265E+2
fDecimal floating point392.65
gUse the shorter of %e or %f392.65
GUse the shorter of %E or %f392.65
oSigned octal610
sString of characterssample
uUnsigned decimal integer7235
xUnsigned hexadecimal integer7fa
XUnsigned hexadecimal integer (capital letters)7FA
pPointer addressB800:0000
nNothing printed. The argument must be a pointer to a signed int, where the number of characters written so far is stored.
%% followed by another % character will write % to the stream.


The tag can also contain flagswidth.precision and modifiers sub-specifiers, which are optional and follow these specifications:

flagsdescription
-Left-justify within the given field width; Right justification is the default (see width sub-specifier).
+Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign.
(space)If no sign is going to be written, a blank space is inserted before the value.
#Used with ox or X specifiers the value is preceeded with 00x or 0X respectively for values different than zero.
Used with eE and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written.
Used with g or G the result is the same as with e or E but trailing zeros are not removed.
0Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).


widthdescription
(number)Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
*The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.


.precisiondescription
.numberFor integer specifiers (diouxX): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
For eE and f specifiers: this is the number of digits to be printed after de decimal point.
For g and G specifiers: This is the maximum number of significant digits to be printed.
For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.
For c type: it has no effect.
When no precision is specified, the default is 1. If the period is specified without an explicit value for precision0 is assumed.
.*The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.


lengthdescription
hThe argument is interpreted as a short int or unsigned short int (only applies to integer specifiers: idoux and X).
lThe argument is interpreted as a long int or unsigned long int for integer specifiers (idoux and X), and as a wide character or wide character string for specifiers c ands.
LThe argument is interpreted as a long double (only applies to floating point specifiers: eEfg and G).


additional arguments
Depending on the format string, the function may expect a sequence of additional arguments, each containing one value to be inserted instead of each %-tag specified in theformat parameter, if any. There should be the same number of these arguments as the number of %-tags that expect a value.


Return Value

On success, the total number of characters written is returned.
On failure, a negative number is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* fprintf example */
#include <stdio.h>

int main ()
{
   FILE * pFile;
   int n;
   char name [100];

   pFile = fopen ("myfile.txt","w");
   for (n=0 ; n<3 ; n++)
   {
     puts ("please, enter a name: ");
     gets (name);
     fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
   }
   fclose (pFile);

   return 0;
}


This example prompts 3 times the user for a name and then writes them to myfile.txt each one in a line with a fixed length (a total of 19 characters + newline). 
Two format tags are used:
%d : Signed decimal integer
%-10.10s : left aligned (-), minimum of ten characters (10), maximum of ten characters (.10), String (s) .
Assuming that we have entered JohnJean-Francois and Yoko as the 3 names, myfile.txt would contain:

myfile.txt
Name 1 [John      ] 
Name 2 [Jean-Franc] 
Name 3 [Yoko      ] 

posted @ 2010-12-27 12:16 Eping 阅读(441) | 评论 (0)编辑 收藏

2010年10月4日

去掉拷贝源代码前面的行号

说明:有时候我们从网上或电子书中拷贝的源代码是有行号的,但我们又希望拷贝的代码可以直接使用?怎么办呢?
一、自己写个工具
二、网上找个工具
三、使用功能强大的编辑工具如editplus
本文使用的就是editplus,用editplus打开源代码文件[带行号的源代码文件]。按CURL+H 选上正则表达式 这个勾勾  在查到里输入以下正则表达式:
([0-9]+ )
注间: 表达式表示 前面为数字,后面为空格的  如下面这些代码可以使用这个表达式,但如果 源代码中出现有 “123 abc”这样的字符那么123 [123空格]这样的字符串也会被替换掉,所以要千万小心。
1 <HTML>
2 <HEAD>
3 <TITLE>Scriptable Plug-in Test</TITLE>
4 </HEAD>
5 <BODY id="bodyId">
正则表达式为: ([0-9]+\.)  则能找到 数字. 这样格式的 字符串   \相当于转义字符。
如  :
1.   printf("hello world");
2.  printf("\n");

posted @ 2010-10-04 17:57 Eping 阅读(1019) | 评论 (0)编辑 收藏

2010年9月19日

Linux字符界面浏览器

     一、lynx
ubuntu下安装:sudo apt-get install lynx-cur
二、m3w ubuntu默认已经安装  用法:m3w  www.eping.net

posted @ 2010-09-19 14:40 Eping 阅读(1421) | 评论 (0)编辑 收藏

2010年9月13日

ubuntu编译libcurl

一、下载libcurl http://curl.haxx.se/download/curl-7.21.1.tar.gz
二、安装   指定了安装目录     /usr/local/curl
命令1: ./configure --prefix=/usr/local/curl
结果:

  curl version:    7.21.1
  Host setup:      i686-pc-linux-gnu
  Install prefix:  /usr/local/curl
  Compiler:        gcc
  SSL support:     enabled (OpenSSL)
  SSH support:     no      (--with-libssh2)
  zlib support:    enabled
  krb4 support:    no      (--with-krb4*)
  GSSAPI support:  no      (--with-gssapi)
  SPNEGO support:  no      (--with-spnego)
  resolver:        default (--enable-ares / --enable-threaded-resolver)
  ipv6 support:    enabled
  IDN support:     enabled
  Build libcurl:   Shared=yes, Static=yes
  Built-in manual: enabled
  Verbose errors:  enabled (--disable-verbose)
  SSPI support:    no      (--enable-sspi)
  ca cert bundle:  /etc/ssl/certs/ca-certificates.crt
  ca cert path:    no
  LDAP support:    enabled (OpenLDAP)
  LDAPS support:   enabled
  RTSP support:    enabled
  RTMP support:    no      (--with-librtmp)
  Protocols:       DICT FILE FTP FTPS HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTSP SMTP SMTPS TELNET TFTP
命令2:make
命令3:sudo make install
可以看到lib库,已经安装在 /usr/local/curl/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/curl/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
在安装目录下/usr/local/curl下会有四个目录 bin  include  lib  share 包含了所需的库、头文件等

posted @ 2010-09-13 11:30 Eping 阅读(6378) | 评论 (0)编辑 收藏

libcurl简介

libcurl ——多协议传输库

什么是libcurl——libcurl是免费的、开源的、容易使用的客户端URL传输库,支持DICTFILEFTPFTPGOPHERHTTPHTTPSIMAPIMAPSLDAPLDAPSPOP3POP3SRTMPTRSPSCPSFTPSMTPSMTPSTELNETFTFP等协议。此外Libcurl还支持安全套接字[SSL]HTTP POSTHTTP PUTFTP上传及基于HTTP表单的上传,不仅如此它还支持代理、cookies、用户+密码的授权认证、文件传输恢复、HTTP隧道代理等等。

       Libcurl不仅是个轻量级的网络库,而且是跨平台的网络库。Libcurl可以在多个平台上编译使用。包括SolarisNetBSDFreeBSDOpenBSDDarwinHPUXIRIXRIXTru64LinuxUnixWareHURDWindowsAmigaOS/2BeOsMAX OS XUltrixQNXOpenVMSRISC OSNovell NetWareDOS等操作系统。

       除此之外,libcurl还具有线程安全,兼容IPv6、功能丰富、容易使用等特点。目前libcurl已在许多知名的公司和应用程序中广泛使用。


posted @ 2010-09-13 11:08 Eping 阅读(1092) | 评论 (0)编辑 收藏

2010年9月9日

[转]ubuntu mysql源码安装

一、安装Mysql
1、sudo apt-get install g++ gcc make automake perl libncurses5-dev kdelibs_dev kdelib
安装 ncurses-5.6
(确保需要的工具完好安装)
2、cd ~/Downloads
(进入压缩包所在目录)
3、tar zxvf mysql-6.0.2-alpha.tar.gz
(解压到此处)
4、cd mysql-6.0.2-alpha
(进入解压出来的源码包文件夹)
5、 ./configure --prefix=/usr/local/mysql
(指定安装路径)
6、make
(编译安装程序)
7、sudo make install
(进行安装)
8、sudo cp support-files/my-medium.cnf /etc/my.cnf
(复制源码包内的设置文件到/etc/系统统一的设置文件路径)
9、sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/
sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
sudo ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/
sudo ln -s /usr/local/mysql/bin/mysql_conf /usr/bin/
sudo ln -s /usr/local/mysql/share/mysql/mysql.server /usr/bin/
(添加执行程序的软链接,这只是为了方便,喜欢用完整路径的可以不做)
10、sudo groupadd mysql
(创建用户组mysql)
11、sudo useradd -g mysql mysql
(在用户组mysql下创建用户mysql)
12、cd /usr/local/mysql
(进入主程序目录)
13、sudo bin/mysql_install_db --user=mysql
(如果还没有安装的MySQL,必须创建MySQL授权表。创建后,需要手动重新启动服务器)
14、sudo chown -R root .
(使/usr/local/mysql/目录下所有文件为根用户root所有)
15、sudo chown -R mysql var
(使/usr/local/mysql/var/目录下所有文件为用户mysql所有)
16、sudo chgrp -R mysql .
(使/usr/local/mysql/目录下所有文件为用户组mysql所有)
17、sudo bin/mysql_safe --use=mysql &
(初始化并测试你的mysql,其中&为后台执行的意思)

二、启动Mysql Server
mysql_config
mysqld_safe --user=mysql &
mysql.server start

三、设置自启动
1、sudo cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
2、sudo chmod +x mysql

四、添加Mysql用户密码
1、确保Mysql Server已启动
2、mysql -u root -p
3、SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
4、SET PASSWORD FOR 'root'@'hostname' = PASSWORD('newpwd');
(hostname是你的主机名,按实际情况而定,)

posted @ 2010-09-09 19:59 Eping 阅读(623) | 评论 (0)编辑 收藏

mysql源码下载

http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-5.1/mysql-5.1.50.tar.gz

posted @ 2010-09-09 16:28 Eping 阅读(234) | 评论 (0)编辑 收藏

mysql源码下载及安装

一、Mysql下载 http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-5.1/mysql-5.1.50.tar.gz 
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
shell> chown -R root  .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &

posted @ 2010-09-09 11:27 Eping 阅读(1461) | 评论 (0)编辑 收藏

Linux安装Apache服务器

一、下载Apache http 服务器
    目前最新为httpd-2.2.16 http://httpd.apache.org/download.cgi
二、解压Apache
    tar -xzvf  httpd-2.2.16.tar.gz
三、进入httpd-2.2.16 目录
./configure
make
sudo make install //我使用的是ubuntu系统
默认情况下apache 安装在  /usr/local/apache2
四、配置apche
/usr/local/apache2/conf/httpd.conf
五、启动 apche /关闭  /重启
sudo ./bin/apachectl start   /stop /restart




posted @ 2010-09-09 00:40 Eping 阅读(294) | 评论 (0)编辑 收藏