fprintf() 、sprintf、snprintf:int fprintf(FILE *stream, const char *format, ...);int sprintf(char *str, const char *format, ...);int snprintf(char *str,...
为了解决溢出,采用char数组。为了简洁,不用每个位挨个计算,采用递归#includeFILE *fp;void prit(char data[]){ int i=0; while(data[i]=='0') i++; while(data[i]) { fprintf(fp,"%c",data[.....
分类:
其他好文 时间:
2014-09-02 22:37:25
阅读次数:
167
1、应用与原理
在C语言中又是我们无法给出一个函数参数的列表,比如:
int printf(const char *format, ...); int fprintf(FILE *stream, const char *format, ...);
这是我们使用到了可以变参数,也就是使用...代表0个或多个参数。
那么编译器如何获取/...
分类:
其他好文 时间:
2014-09-02 09:06:44
阅读次数:
362
自己写一些小代码的时候总是用fprintf来写log,感觉这样不太科学,还是写一个通用的简单带log level的log类,以后就拿来复用吧。这个类实现了非常简单的功能:如果指定了log文件path和name创建一个log文件,并将各种level的写入文件中,否则都打印到屏幕,格式如下:
[DEBUG] : xxxxx
[WARN] : xxxx
[MSG] : xxxxx
代码:
//...
分类:
其他好文 时间:
2014-08-25 22:57:15
阅读次数:
274
在C程序中,文件由文件指针或者文件描述符表示。ISO C的标准I/0库函数(fopen, fclose, fread, fwrite, fscanf, fprintf等)使用文件指针,UNIX的I/O函数(open, close, read, write, ioctl)使用文件描述符。下面重点来说下...
分类:
编程语言 时间:
2014-08-20 16:15:52
阅读次数:
274
前几天写类linux文件系统的时候,被这个搞死了,今天终于弄懂了
这是cpp文件
#include
#include
#include
#include
using namespace std;
char ch[250];
struct s{
short a, b;
};
int main(){
FILE *file = fo...
分类:
其他好文 时间:
2014-08-18 10:53:04
阅读次数:
395
#include
#include
#include
int main(int argc,char **argv)
{
CvCapture* capture = NULL;
IplImage* pImg = NULL;
IplImage* pImg1 = NULL;
fprintf(s...
分类:
其他好文 时间:
2014-08-18 10:50:14
阅读次数:
895
1. 需要写入非ascii文本并且与本地编码无关时,除了utf8,unicode编码是另外一个选择,它的好处是占两个字节,便于统计字符和对字符进行处理,因为有对应的宽字节的函数,如wcslen.
2.需要注意的亮点,要先写入0xff,0xfe文件头,之后使用fwprintf时用%S(大写)格式写入宽字节字符串。
3.使用_wfopen支持中文路径....
分类:
编程语言 时间:
2014-08-14 10:53:58
阅读次数:
301
fprintf输出到文件中,sprintf输出到字符串中.
如:
fprintf(fp,"%s",name);
fp为文件指针
sprintf(buff,"%s",name);
buff为字符数组
分类:
其他好文 时间:
2014-08-07 21:35:20
阅读次数:
197
1. ##的功能是将其后面的宏参数进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号1 #define WARN_IF(EXP) /2 do{ if (EXP) /3 fprintf(stderr, "Warning: " ...
分类:
其他好文 时间:
2014-08-05 18:49:59
阅读次数:
585