免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1126 | 回复: 0

C语言实现myql中存取二进制文件 [复制链接]

论坛徽章:
0
发表于 2006-04-14 23:47 |显示全部楼层
用C把二进制文件(

CODE:
#include
#include
#include
#include
#include
#include
#define host                "localhost"              //mysql server
#define username        "root"
#define password        "cipher"
#define database         "www"
   
int get_file_size(char *path, off_t *size)
{
        struct stat file_stats;
        if(stat(path, &file_stats))
                return -1;
        *size = file_stats.st_size;
        return 0;
}
int main(int argc, char *argv[])
{
        char  *filename;
        off_t *size;
        MYSQL            *conn;
        MYSQL_RES    *res_set;
        MYSQL_ROW    row;
        MYSQL_FIELD *field;
        int                    i, flag;
        char                *sql;
        FILE                *fp;
        char                *buf;
        int                    n=0;
        char                *end;
        unsigned long *length;        
        
        if (argc != 2) {
                printf("Usage: %s srcfile\n", argv[0]);
                exit(1);
        }
        filename = argv[1];
        if ((get_file_size(filename, size)) == -1) {
                perror("get file size" );
                exit(1);
        }
        
        if ((buf = (char *)malloc(sizeof(char)*(*size+1))) == NULL) {
                perror("malloc buf" );
                exit(1);
        }
        if ((fp = fopen(filename, "rb" )) == NULL) {
                perror("fopen file" );
                exit(1);
        }
        if ((n = fread(buf, 1, *size, fp))
Makefile

CODE:

CXX = gcc
LIBS = -lmysqlclient
PRODUCT = mysql_binary
.LIBPATTERNS: lib%.so lib%.a
vpath %   .
vpath %.c src
vpath %.h include
OBJS = mysql_binary.o
$(PRODUCT): $(OBJS)  
        $(CXX) $(OBJS) -o $@ $(LIBS)
.c.o:
.PHONY:clean
clean:
        -rm -f $(OBJS) $(PRODUCT)

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/9380/showart_100060.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP