当前位置: 编程技术>c/c++/嵌入式
C语言嵌入informix基础入门示例讲解
来源: 互联网 发布时间:2014-10-22
本文导语: 代码如下:#include #include #include #include $struct _db_person{ char name[30+1]; char card[12+1]; int age;};char *trim(char *str){ char *p, *buffer; int len; if( NULL!=str ) { len = strlen(str); if...
代码如下:
#include
#include
#include
#include
$struct _db_person
{
char name[30+1];
char card[12+1];
int age;
};
char *trim(char *str)
{
char *p, *buffer;
int len;
if( NULL!=str )
{
len = strlen(str);
if( len > 0 )
{
buffer=(char *)malloc(sizeof(char)*(len+1));
if( NULL != buffer )
{
memmove(buffer, str, len);
buffer[len]=0;
p = buffer + len - 1;
while( (p != buffer) && ((*p > 0x00) && (*p 0x00) && (*p name,sizeof(pps->name),stdin);
trim(pps->name);
if( strlen(pps->name) == 0 )
return -1;
printf("enter card no: ");
fgets(pps->card,sizeof(pps->card),stdin);
trim(pps->card);
if( strlen(pps->card) == 0 )
return -2;
printf("enter age: ");
fgets(strage,sizeof(strage),stdin);
trim(strage);
if( strlen(strage) == 0 )
return -3;
pps->age = atoi(strage);
return 0;
}
int main(void)
{
$struct _db_person dbps;
$database exec01;
if( SQLCODE != 0 )
{
printf("open demo1 failure,SQLCODE=%dn",SQLCODE);
return -1;
}
while( 1 )
{
if( GetData(&dbps)