- 浏览: 61685 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
brxonline:
提示不能这样写234390216 写道234390216 写道 ...
mysql导出数据为excel -
234390216:
234390216 写道不行啊,错误
提示不能这样写
mysql导出数据为excel -
234390216:
不行啊,错误
mysql导出数据为excel
1.流的定向
freopen函数清除一个流的定向,fwide设置流的定向
#include <stdio.h>
#include <wchar.h>
int fwide(FILE *fp, int mode);
如果mode的参数值为负,fwide将试图使指定的流是字节定向的。
如果mode的参数值为正,fwide将试图使指定的流是宽定向的。
如果mode的参数值为0,fwide将不试图设置流的定向, 但返回标识该流定向的值。
2.缓冲
标准IO提供了三种类型的缓冲:
全缓冲
行缓冲
不带缓冲
有两个函数可以更改缓冲类型
#include <stdio.h>
void setbuf(FILE *restrict fp, char *restrict buf);
int setvbuf(FILE *restrict fp, char *restrict buf,
int mode,
size_t size);
任何时候我们都可以强制冲洗一个流
#include <stdio.h>
int fflush(FILE *fp);
3.打开流
#include <stdio.h>
FILE *fopen(const char *restrict pathname, const
char *restrict type);
FILE *freopen(const char *restrict pathname, const
char *restrict type,
FILE *restrict fp);
FILE *fdopen(int filedes, const char *type);
type参数指定对IO流的读、写方式
r or rb 为读而打开
w or wb 把文件截短至0,或为写而打开
a or ab 添加,为在文件尾写而打开,或为写而创建
r+ or r+b or rb+ 为读和写而打开
w+ or w+b or wb+ 把文件截短至0长,或为读和写而打开
a+ or a+b or ab+ 为在文件尾读和写而打开或创建
4.读写流
一次读一个字符
#include <stdio.h>
int getc(FILE *fp);
int fgetc(FILE *fp);
int getchar(void);
不管是出错还是到达文件尾端,这三个函数都返回同样的值。为了区分这两种情况必须用下面两个函数
#include <stdio.h>
int ferror(FILE *fp);
int feof(FILE *fp);
清除标志
void clearerr(FILE *fp);
从流中读取数据后,可以调用ungetc将字符再压送回流中
#include <stdio.h>
int ungetc(int c, FILE *fp);
每次输出一个字符的函数
#include <stdio.h>
int putc(int c, FILE *fp);
int fputc(int c, FILE *fp);
int putchar(int c);
每次一行函数
#include <stdio.h>
char *fgets(char *restrict buf, int n, FILE
*restrict fp);
char *gets(char *buf);
#include <stdio.h>
int fputs(const char *restrict str, FILE *restrict
fp);
int puts(const char *str);
二进制读写
#include <stdio.h>
size_t fread(void *restrict ptr, size_t size,
size_t nobj,
FILE *restrict fp);
size_t fwrite(const void *restrict ptr, size_t
size, size_t nobj,
FILE *restrict fp);
5.定位流
#include <stdio.h>
long ftell(FILE *fp);
Returns: current file position indicator if OK, 1L on error
int fseek(FILE *fp, long offset, int whence);
Returns: 0 if OK, nonzero on error
void rewind(FILE *fp);
#include <stdio.h>
off_t ftello(FILE *fp);
Returns: current file position indicator if OK, (off_t)1 on error
int fseeko(FILE *fp, off_t offset, int whence);
#include <stdio.h>
int fgetpos(FILE *restrict fp, fpos_t *restrict pos);
int fsetpos(FILE *fp, const fpos_t *pos);
6.格式化输出和输入
格式化输出
#include <stdio.h>
int printf(const char *restrict format, ...);
int fprintf(FILE *restrict fp, const char
*restrict format, ...);
format说明
%[flags][fldwidth][precision][lenmodifier]convtype
四种格式函数变体
#include <stdarg.h>
#include <stdio.h>
int vprintf(const char *restrict format, va_list arg);
int vfprintf(FILE *restrict fp, const char
*restrict format,
va_list arg);
Both return: number of characters output if OK, negative value if output error
[View full width]
int vsprintf(char *restrict buf, const char
*restrict format,
va_list arg);
int vsnprintf(char *restrict buf, size_t n,
const char *restrict format, va_list
arg);
Both return: number of characters output if OK, negative value if output error
[View full width]
int sprintf(char *restrict buf, const char
*restrict format, ...);
int snprintf(char *restrict buf, size_t n,
const char *restrict format, ...);
格式化输入
#include <stdio.h>
int scanf(const char *restrict format, ...);
int fscanf(FILE *restrict fp, const char *restrict
format, ...);
int sscanf(const char *restrict buf, const char
*restrict format,
...);
#include <stdarg.h>
#include <stdio.h>
int vscanf(const char *restrict format, va_list arg);
int vfscanf(FILE *restrict fp, const char
*restrict format,
va_list arg);
int vsscanf(const char *restrict buf, const char
*restrict format,
va_list arg);
7.临时文件
两个函数帮助创建临时文件
#include <stdio.h>
char *tmpnam(char *ptr);
Returns: pointer to unique pathname
FILE *tmpfile(void);
例:
#include "apue.h"
int
main(void)
{
char name[L_tmpnam], line[MAXLINE];
FILE *fp;
printf("%s\n", tmpnam(NULL)); /* first temp name */
tmpnam(name); /* second temp name */
printf("%s\n", name);
if ((fp = tmpfile()) == NULL) /* create temp file */
err_sys("tmpfile error");
fputs("one line of output\n", fp); /* write to temp file */
rewind(fp); /* then read it back */
if (fgets(line, sizeof(line), fp) == NULL)
err_sys("fgets error");
fputs(line, stdout); /* print the line we wrote */
exit(0);
}
#include <stdio.h>
char *tempnam(const char *directory, const char
*prefix);
#include <stdlib.h>
int mkstemp(char *template);
例:
#include "apue.h"
int
main(int argc, char *argv[])
{
if (argc != 3)
err_quit("usage: a.out <directory> <prefix>");
printf("%s\n", tempnam(argv[1][0] != ' ' ? argv[1] : NULL,
argv[2][0] != ' ' ? argv[2] : NULL));
exit(0);
}
freopen函数清除一个流的定向,fwide设置流的定向
#include <stdio.h>
#include <wchar.h>
int fwide(FILE *fp, int mode);
如果mode的参数值为负,fwide将试图使指定的流是字节定向的。
如果mode的参数值为正,fwide将试图使指定的流是宽定向的。
如果mode的参数值为0,fwide将不试图设置流的定向, 但返回标识该流定向的值。
2.缓冲
标准IO提供了三种类型的缓冲:
全缓冲
行缓冲
不带缓冲
有两个函数可以更改缓冲类型
#include <stdio.h>
void setbuf(FILE *restrict fp, char *restrict buf);
int setvbuf(FILE *restrict fp, char *restrict buf,
int mode,
size_t size);
任何时候我们都可以强制冲洗一个流
#include <stdio.h>
int fflush(FILE *fp);
3.打开流
#include <stdio.h>
FILE *fopen(const char *restrict pathname, const
char *restrict type);
FILE *freopen(const char *restrict pathname, const
char *restrict type,
FILE *restrict fp);
FILE *fdopen(int filedes, const char *type);
type参数指定对IO流的读、写方式
r or rb 为读而打开
w or wb 把文件截短至0,或为写而打开
a or ab 添加,为在文件尾写而打开,或为写而创建
r+ or r+b or rb+ 为读和写而打开
w+ or w+b or wb+ 把文件截短至0长,或为读和写而打开
a+ or a+b or ab+ 为在文件尾读和写而打开或创建
4.读写流
一次读一个字符
#include <stdio.h>
int getc(FILE *fp);
int fgetc(FILE *fp);
int getchar(void);
不管是出错还是到达文件尾端,这三个函数都返回同样的值。为了区分这两种情况必须用下面两个函数
#include <stdio.h>
int ferror(FILE *fp);
int feof(FILE *fp);
清除标志
void clearerr(FILE *fp);
从流中读取数据后,可以调用ungetc将字符再压送回流中
#include <stdio.h>
int ungetc(int c, FILE *fp);
每次输出一个字符的函数
#include <stdio.h>
int putc(int c, FILE *fp);
int fputc(int c, FILE *fp);
int putchar(int c);
每次一行函数
#include <stdio.h>
char *fgets(char *restrict buf, int n, FILE
*restrict fp);
char *gets(char *buf);
#include <stdio.h>
int fputs(const char *restrict str, FILE *restrict
fp);
int puts(const char *str);
二进制读写
#include <stdio.h>
size_t fread(void *restrict ptr, size_t size,
size_t nobj,
FILE *restrict fp);
size_t fwrite(const void *restrict ptr, size_t
size, size_t nobj,
FILE *restrict fp);
5.定位流
#include <stdio.h>
long ftell(FILE *fp);
Returns: current file position indicator if OK, 1L on error
int fseek(FILE *fp, long offset, int whence);
Returns: 0 if OK, nonzero on error
void rewind(FILE *fp);
#include <stdio.h>
off_t ftello(FILE *fp);
Returns: current file position indicator if OK, (off_t)1 on error
int fseeko(FILE *fp, off_t offset, int whence);
#include <stdio.h>
int fgetpos(FILE *restrict fp, fpos_t *restrict pos);
int fsetpos(FILE *fp, const fpos_t *pos);
6.格式化输出和输入
格式化输出
#include <stdio.h>
int printf(const char *restrict format, ...);
int fprintf(FILE *restrict fp, const char
*restrict format, ...);
format说明
%[flags][fldwidth][precision][lenmodifier]convtype
四种格式函数变体
#include <stdarg.h>
#include <stdio.h>
int vprintf(const char *restrict format, va_list arg);
int vfprintf(FILE *restrict fp, const char
*restrict format,
va_list arg);
Both return: number of characters output if OK, negative value if output error
[View full width]
int vsprintf(char *restrict buf, const char
*restrict format,
va_list arg);
int vsnprintf(char *restrict buf, size_t n,
const char *restrict format, va_list
arg);
Both return: number of characters output if OK, negative value if output error
[View full width]
int sprintf(char *restrict buf, const char
*restrict format, ...);
int snprintf(char *restrict buf, size_t n,
const char *restrict format, ...);
格式化输入
#include <stdio.h>
int scanf(const char *restrict format, ...);
int fscanf(FILE *restrict fp, const char *restrict
format, ...);
int sscanf(const char *restrict buf, const char
*restrict format,
...);
#include <stdarg.h>
#include <stdio.h>
int vscanf(const char *restrict format, va_list arg);
int vfscanf(FILE *restrict fp, const char
*restrict format,
va_list arg);
int vsscanf(const char *restrict buf, const char
*restrict format,
va_list arg);
7.临时文件
两个函数帮助创建临时文件
#include <stdio.h>
char *tmpnam(char *ptr);
Returns: pointer to unique pathname
FILE *tmpfile(void);
例:
#include "apue.h"
int
main(void)
{
char name[L_tmpnam], line[MAXLINE];
FILE *fp;
printf("%s\n", tmpnam(NULL)); /* first temp name */
tmpnam(name); /* second temp name */
printf("%s\n", name);
if ((fp = tmpfile()) == NULL) /* create temp file */
err_sys("tmpfile error");
fputs("one line of output\n", fp); /* write to temp file */
rewind(fp); /* then read it back */
if (fgets(line, sizeof(line), fp) == NULL)
err_sys("fgets error");
fputs(line, stdout); /* print the line we wrote */
exit(0);
}
#include <stdio.h>
char *tempnam(const char *directory, const char
*prefix);
#include <stdlib.h>
int mkstemp(char *template);
例:
#include "apue.h"
int
main(int argc, char *argv[])
{
if (argc != 3)
err_quit("usage: a.out <directory> <prefix>");
printf("%s\n", tempnam(argv[1][0] != ' ' ? argv[1] : NULL,
argv[2][0] != ' ' ? argv[2] : NULL));
exit(0);
}
发表评论
-
UNIX网络编程(1)-简介
2011-10-06 17:31 7541.bzero函数 bzero 等同于memset(void ... -
UNIX编程(15)-进程间通信
2011-08-07 12:09 1085. 管道 #include <un ... -
UNIX编程(14)-高级IO
2011-08-03 21:36 13781.非阻塞IO 对于一个给定的描述符有两种方法对其指定非阻塞 ... -
UNIX编程(13)-守护进程
2011-08-02 21:59 9261.守护进程的编程规则 1)用umask将文件模式创建屏蔽字 ... -
UNIX编程(12)-线程控制
2011-07-27 15:26 9121.线程限制 某些系统有线程的限制,可以通过sysconf函 ... -
UNIX编程(11)-线程
2011-07-27 14:34 9501.线程标识 每个线程都有一个线程ID,线程ID只在它所属的 ... -
UNIX编程(10)-信号
2011-07-20 21:18 9741.signal函数 #include ... -
UNIX编程(9)-进程关系
2011-07-12 14:41 11071.终端登录 2.网络登录 3.进程组 ... -
UNIX编程(8)-进程控制
2011-07-09 11:37 11631.进程标识符 每个进程 ... -
UNIX编程(7)-进程环境
2011-07-01 15:07 8691.main 函数 c程序总是从main函数开始执行,当内核 ... -
UNIX编程(6)-系统数据文件和信息
2011-06-28 16:35 11701.口令文件 口令文件存储在/etc/passwd中,是一个A ... -
UNIX编程(4)-文件和目录
2011-06-23 16:56 12471.stat,fstat,lstat函数 #include & ... -
UNIX编程(3)-文件IO
2011-06-21 17:45 14121.open函数 #include <fcntl.h&g ... -
UNIX编程(2)-UNIX标准化
2011-06-15 11:41 6761.ISO c 2.IEEE POSIX 3.Single U ... -
UNIX编程(1)-基础知识
2011-06-15 10:54 8081.登陆名 登陆名放在/etc ...
相关推荐
UNIX环境高级编程一套电子书! 一共23部分19章。最后4部分为:函数原型、其它源码、习题答案、参考资料 如果您对某章节感兴趣,则下载非常方便! 如果此资源有侵权,请通知我,我会及时撤销下载!
《TCP/IP 详解》(3卷),《UNIX网络编程》(2卷)参考书2:《Linux系统编程》RobertLoVe [美] 参考书3:《Linux/UNIX系统编
Unix域协议:实现 17.1 概述 180 17.2 代码介绍 180 17.3 Unix domain和protosw结构 181 17.4 Unix域插口地址结构 182 17.5 Unix域协议控制块 183 17.6 uipc_usrreq函数 185 17.7 PRU_ATTACH请求和unp_attach函数 ...
UNIX系统标准IO应用编程.ppt
UNIX环境高级编程一套电子书! 一共23部分19章。最后4部分为:函数原型、其它源码、习题答案、参考资料 如果您对某章节感兴趣,则下载非常方便! 如果此资源有侵权,请通知我,我会及时撤销下载!
Unix域协议:概述 16.1 概述 175 16.2 用途 176 16.3 性能 177 16.4 编码举例 177 16.5 小结 179
Linux&UNIX;系统编程手册源码副本
适用于编程初学者,不给你们看
第5章标准IO库 第6章系统数据文件和信息 第7章U N I X进程的环境 第8章进程控制 第9章进程关系 第10章信号 第11章终端IO 第12章高级IO 第13章精灵进程 第14章进程间通信 第15章高级进程间通信 第16章数据库函数库 .....
Unix域协议:I/O和描述符的传递 18.1 概述 210 18.2 PRU_SEND和PRU_RCVD请求 210 18.3 描述符的传递 214 18.4 unp_internalize函数 218 18.5 unp_externalize函数 220 18.6 unp_discard函数 221 18.7 unp_dispose...
Linux系统是一个免费使用和自由传播的类Unix操作系统,基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统,Linux是许多企业...
05 标准IO库.pdf 06 系统数据文件和信息.pdf 07 UNIX进程的环境.pdf 08 进程控制.pdf 09 进程关系.pdf 10 信号.pdf 11 终端IO.pdf 12 高级IO.pdf 13 精灵进程.pdf 14 进程间通信.pdf 15 高级进程间通信....
关于c语音UNIX系统高级编程,涉及到UNIX主要的个方面。文件结构、IO库、进程管理里、进程间通讯的算法。学习UNIX环境高级编程的经典。
书中除了介绍UNIX文件和目录、标准I/O库、系统数据文件和信息、进程环境、进程控制、进程关系、信号、线程、线程控制、守护进程、各种I/O、进程间通信、网络IPC、伪终端等方面的内容,还在此基础上介绍了多个应用...
UNIX高级环境编程,进程、线程及其通信,标准IO
本课程主要讲述在Unix/Linux环境下高级编程的方法,其内容包括文件、信号、POSIX线程、UDP、WEB和客户机服务器等相关知识,并由浅入深讲述通信、并发和多线程编程的核心技术、实用技术。 前导课程: ①操作系统原理 ...
它封装了网络编程的复杂性, 使网络编程和 Web 技术的最新进展能够被比以往更广泛的开发人员接触到。 Netty 不只是一个接口和类的集合;它还定义了一种架构模型以及一套丰富的设计模式。 该资源就是开发Netty程序...
1.3 Linux与UNIX的异同 5 1.4 操作系统类型选择和内核版本的选择 5 1.4.1 常见的不同公司发行的Linux异同 6 1.4.2 内核版本的选择 6 1.5 Linux的系统架构 7 1.5.1 Linux内核的主要模块 7 1.5.2 Linux的...
学习linux编程的主要课程之一的unix网络编程,讲述了线程通信和系统IO的关系