---------------------------------------------------------------------------------------------------------------------------------
回调函数:callback
注意: 1.找到匹配的数据时才会调用该回调函数,如果该函数没有被调用 2.说明未找到匹配的数据 3.每找到一个符合条件的数据就会调用一次callback 4.参数含义: arg:sqlite3_exec的第4个参数 col:找到的数据有几列 pcontent:找到的这几行数据字符串首地址的指针数组 ptitle:找到的这几列标题字符串首地址的指针数组
---------------------------------------------------------------------------------------------------------------------------------
fprintf和sprintf的区别
fprintf和sprintf的区别
1、fprintf:
格式化输出到流(stream)文件中,返回值是输出的字符数,发生错误时返回一个负值.
#include <stdio.h>
int fprintf( FILE *stream, const char *format, ... );
2、sprintf:
格式化输出发送到buffer(缓冲区)中.返回值是写入的字符数量.
#include <stdio.h>
int sprintf( char *buffer, const char *format, ... );
3.区别:
(1)输出目标不同:`fprintf` 将格式化数据输出到文件流 而 `sprintf` 将格式化数据写入到字符串。
(2)参数类型不同:`fprintf` 的第一个参数是 文件流指针, `sprintf` 的第一个参数是 目标字符串的指针。
(3)使用注意事项:`sprintf` 需要确保目标字符串 `str` 有足够的空间来存储格式化后的数据, 以避免缓冲区溢出
---------------------------------------------------------------------------------------------------------------------------------
标准流 stdin、stdout、stderr
stdin、stdout、stderr 分别指向标准流相关联的 FILE 对象
其中
stdin 标准输入流
stdout 标准输出流
stderr 标准错误流
相关联的 FILE 对象
在用C去写文件时用到下面命令
File *fp=fopen()
1
这个fp就是我们向系统申请的,相当于一通往文件的通道。
其实,stdin,stdout,stderr就是这个fp,不过他是随着计算机系统的开启默认打开的。
在写C程序时经常遇到的 printf(),fprintf(),perror() 中
printf() 其实就是向stdout中输出,等同于 fprintf(stdout,“****”)
perror() 其实就是向stderr中输出,等同于 fprintf(stderr,“***”)
stdout 和 stderr 的区别
缓冲区
stdout默认是行缓冲,也就是它遇到 \n,才向外输出内容
stderr是没有缓冲的,它立即输出
(如果你想stdout也实时输出内容,那就在输出语句后加上fflush(stdout))
具体区别,思考下面代码
#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;
int main()
{
fprintf(stdout, "hello");
fprintf(stderr, "world!");
cout<<endl;
}
1
2
3
4
5
6
7
8
9
10
输出:world!hello