求助基于嵌入式Linux的智能停车场收费系统的C语言代码,网上找的就是缺失一部分
客户端:
struct msg{
char cardID[10];
int flag;
char username[10];
};
int main()
{
int fd;
char cardnum1[10];
char cardnum2[10];
//char buf[50] = "hello";
struct msg m;
while(1){
printf("请第一次输入卡号:");
scanf("%s",cardnum1);
fd = set_connect();
strcpy(m.cardID,cardnum1);
send(fd,&m,sizeof(m),0);
recv(fd,&m,sizeof(m),0);
if(m.flag==1)break;
}
time_t t1;
struct tm *val1;
time(&t1);
val1 = localtime(&t1);
// printf("%d\n",t1);
printf("%d年%d月%d日%d时%d分%d秒\n",val1->tm_year+1900,val1->tm_mon+1,val1->tm_mday,val1->tm_hour,val1->tm_min,val1->tm_sec);
printf("请第二次输入卡号:");
scanf("%s",cardnum2);
time_t t2;
struct tm *val2;
time(&t2);
val2 = localtime(&t2);
// printf("%d\n",t2);
printf("%d年%d月%d日%d时%d分%d秒\n",val2->tm_year+1900,val2->tm_mon+1,val2->tm_mday,val2->tm_hour,val2->tm_min,val2->tm_sec);
printf("请选择你要的消费标准:\n");
printf("1.每秒钟10元钱!\n");
printf("2.每秒钟20元钱!\n");
printf("3.每秒钟30元钱!\n");
printf("请做出你的选择(1-3):");
int s1;
scanf("%d",&s1);
printf("用户名:");
printf("%s\n",m.username);
double t3 = ((double)(t2-t1));
int t4=t3;
printf("本次停车总时长:");
printf("%d",t4);
printf("s\n");
int charge;
/*if(t4>=0&&t4<=30){
charge=10*t4;
}else if(t4>=31&&t4<=60){
charge=20*t4;
}else if(t4>=61&&t4<=90){
charge=30*t4;
}else{
charge=40*t4;
}*/
if(s1==1)
charge=10*t4;
else if(s1==2)
charge=20*t4;
else if(s1==3)
charge=30*t4;
else
printf("你输入的指令有错误!");
printf("本次停车总消费(你选择的单价:%d元/s):",10*s1);
printf("%d",charge);
printf("元\n");
return 0;
}
服务器:
struct msg{
char cardID[10];
int flag;
char username[10];
};
int main()
{
struct msg m;
int fd;
fd = set_connect();
sqlite3 *d1,*d2;
int ret;
char n[10];
int age;
char buf[100];
char **re;
int row,col;
int i;
ret = sqlite3_open("user.db",&d1);
if(ret < 0){
printf("open failed\n");
return -1;
}
recv(fd,&m,sizeof(m),0);
sprintf(buf,"select *from users where cardID='%s'",m.cardID);
sqlite3_get_table(d1,buf,&re,&row,&col,NULL);
if(row>0){
m.flag=1;
}else{
m.flag=0;
}
/*for(i=0;i<=(row + 1)*col -1;i++){
printf("%s\t",re[i]);
if(i%2 != 0)
printf("\n");
}*/
strcpy(m.username,re[2]); //获取用户名
//printf("%s\t",m.username);
send(fd,&m,sizeof(m),0);
return 0;
}