首页 > 学院 > 开发设计 > 正文

通讯录 (纯数据库操作)

2019-11-11 07:45:04
字体:
来源:转载
供稿:网友
#include <stdio.h>#include <sqlite3.h>#include <stdlib.h>void inquire_nocb(sqlite3 *db);int main(){sqlite3 *db;char *sql;char *errmsg;char sql1[100];char name[20];char sex[10];int ret,age; ret=sqlite3_open("data",&db);if(ret != SQLITE_OK){PRintf("open error");exit(1);}sql="create table data(name, sex, age)";ret=sqlite3_exec(db,sql,NULL,NULL,&errmsg);if(ret != SQLITE_OK){printf("creat error");exit(1);}printf("please input name sex  age:/n");scanf("%s %s %d",name,sex,&age);sprintf(sql1,"insert into data values('%s','%s',%d);",name,sex,age);ret=sqlite3_exec(db,sql1,NULL,NULL,&errmsg);if(ret != SQLITE_OK){printf("insert  error");exit(1);}sqlite3_close(db);}void inquire_nocb(sqlite3 *db){int nrow,ncolumn;char **azresult;char *sql;char *errmsg;int ret;int i;sql = "select * from data;";ret = sqlite3_get_table(db,sql,&azresult,&nrow,&ncolumn,&errmsg);if(ret != SQLITE_OK){printf("get table error:%s",errmsg);exit(-1);}printf("nrow = %d,column = %d/n",nrow,ncolumn);for(i = ncolumn;i < (nrow + 1) * ncolumn;i++){printf("%10s",azresult[i]);if((i + 1) % ncolumn == 0){printf("/n");}}sqlite3_free_table(azresult);}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表