判断系统支持汉字否、mysql支持汉字否

create database test;
use test;
create table hanzi (id int(11),name varchar(20));

 

hanzi.c

 #include   <fcntl.h>
 #include <ldap.h>
 #include <iconv.h>
 #include   <sys/types.h>
 #include   <sys/stat.h>
 #include   <stdlib.h>
 #include   <time.h>
 #include   <stdio.h>
 #include   <string.h>
 #include  <sys/socket.h>
 #include  <netinet/in.h>
 #include  <stdarg.h>

 #ifdef   _WIN32
 #include  "c:/mysql/include/mysql.h"
 #else
 #include   <mysql/mysql.h>
 #include   <signal.h>
 #include   <pthread.h>
 #endif
 
#define OUTLEN 256

void mysql_exec(MYSQL  *ldap_billingd,char *sql)
 {
   if ((mysql_query(ldap_billingd,"begin"))<0)
   {
           printf("ldap_billingd: %s",mysql_error(ldap_billingd));
           mysql_query(ldap_billingd,"rollback");
         }
         if ((mysql_query(ldap_billingd,sql))<0)
   {
           printf("ldap_billingd: %s",mysql_error(ldap_billingd));
           mysql_query(ldap_billingd,"rollback");
         }
    mysql_query(ldap_billingd,"commit");
 }
 
int main(int argc,char **argv)
{

 
 FILE* fd=NULL;   
 char line[OUTLEN];
 char lineold[OUTLEN];
 int rc=0;
 char out[OUTLEN];
 MYSQL  *ldap_billingd=NULL;
 char *dbhost_billing="127.0.0.1";
 char *dbuser_billing="root";
 char *dbpassword_billing="";
 int dbport_billing=3306;
 char   sql[1024];
 int id=0;
 
 if (argc!=2)
 {
  printf("usage is :execfilename hanzifilename/n");
  exit(0);
 }

  if ((ldap_billingd= mysql_init(NULL))==NULL)
    {

      printf("ldap_billingd: %s",mysql_error(ldap_billingd));  
    }
  log("mysql_init is finished! /n");  
    if (mysql_real_connect(ldap_billingd,dbhost_billing,dbuser_billing,dbpassword_billing,"test",dbport_billing,NULL,0) <0)
    {
      printf("-----------------ldap_billingd: %s----------------",mysql_error(ldap_billingd));
  }
  printf("mysql_real_connect is finished! /n");

 fd=fopen(argv[1],"r");   
 if (fd==NULL)  
 {     
  printf("mysql real init_init();  fd==NULL   had finished!configfile=%s !/n",argv[1]);  
  exit(1);   
 } 
 id=0;
 while (!feof(fd))  
 {         
  memset(line,0,256);    
  //------读一行字符,该行的字符数不大于num-1------    
  fgets(line,256,fd);


  memset(sql,0,1024);
  sprintf(sql,"insert into hanzi  /
  values('%d','%s') /
  ",id,line);

  mysql_exec(ldap_billingd, sql);
  id++;
 }
}


hanzi.txt
张三
李四
王五


gcc -ggdb3 -I/usr/local/mysql/include/ -L/usr/lib/mysql -lmysqlclient -o hanzi hanzifile.c
./hanzi hanzi.txt

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值