|
ngx1991 发表于 2013-7-26 17:20
msg那个,说来惭愧,正是因为编译的时候说msg初次使用,于是我先char了一个……至于struct加下划线的问题 ...
这是最开始的版本:
#include<ods.h>
#include <stdio.h>
#include <stdlib.h>
#include "treaty.h"
int summer(ods_msg msg);
void show_menu(void)
{
printf("\n----------------------------------\n");
printf("\t\t点餐系统前台终端\n");
printf("\t\tc.查询空桌列表\n");
printf("\t\td.输入被占用空桌\n");
printf("\t\ti.输入空出的餐桌\n");
printf("\t\ts.汇总结账\n");
printf("----------------------------------\n");
}
void *read_all(void *arg)
{
#define LEN 128
int ret = 0;
int fd = *(int *)arg;
ods_msg msg;
while(1){
char buf[LEN];
memset(buf, 0, LEN);
ret = recv(fd, &msg, sizeof(ods_msg), 0);//不断的读从服务器发过来的信息
if(ret == 0)
{
printf("连接终止!\n");
exit(0);
}
printf("接收到信息:%s\n", buf);
}
}
char get_command(void)
{
char com;
scanf("%c", &com);
getchar();
return com;
}
void *input_command(void *arg)
{
int num = 0;
int fd = *(int *)arg;
com command;
char str[LEN];
while(1){
num = read(fd, &command, sizeof(command));
if(num < 0){
perror("read");
exit(1);
}
if(num == 0)
break;
printf("new command: %c\n", command.type);
/*根据命令的类型type做相应处理*/
/*第一步:创建空桌列表,可查询、更改、保存*/
int getop(void);
int getnum(void);
void insert(int); /* insert and delete do not cause an I/O action so no error-checking is needed. */
void delete(int);
void printary(void);
void flushbuffer(void);
static int array[10]={1,2,3,4,5,6,7,8,9,10};
int main(void)
{
while(1){
int num = 0;
int op = getop();
switch(op){
case 'c':
printary();
break;
case 'i':
num = getnum();
if(num>0 && num <11)
insert(num);
else
puts("超出范围");
break;
case 'd':
num = getnum();
if(num>0 && num < 11)
delete(num);
else
puts("超出范围");
break;
default:
puts("错误输入");
}
}
return 0;
}
int getop(void)
{
int buffer = 0;
scanf("%c", &buffer);
flushbuffer();
return buffer;
}
int getnum(void)
{
int buffer = 0;
scanf("%d", &buffer);
flushbuffer();
return buffer;
}
void insert(int a)
{
array[a-1] = a;
}
void delete(int a)
{
array[a-1] = 0;
}
void printary(void)
{
int i;
for(i=0; i<10; ++i)
printf("%d ", array);
printf("\n");
}
void flushbuffer(void)
{
int c;
while((c=getchar())!= '\n')
;
}
/*创建函数sum,根据菜单进行汇总结账*/
int sum(ods_msg msg);
int main(void)
{
int food_count = msg.order_form.food_count;
int sum = 0;
int i;
for (i=0;i<food_count ;++i )
{
int food_price = msg.order_form.food.food_price;
int food_num = msg.order_form.food.food_num;
printf("菜名:%f 单价:%c 数量:%d 菜式总价:%c\n",msg.order_form.food.food_name,msg.order_form.food.food_price,msg.order_form.food.food_num,msg.order_form.food.food_price*msg.order_form.food.food_num);
sum+ = food_price*food_num;
}
printf("总价为 : %c\n", sum);
}
|
|