#include<stdio.h>
#include<signal.h>
#include<unistd.h>
struct product
{
char str[100];
double price;
};
struct product p1;
void mess(int sig)
{
printf("信号代号: %d\n",sig);
printf("商品名为: %s\n",p1.str);
printf("价格为: %.2lf\n",p1.price);
printf("含税价为: %.2lf\n",p1.price*1.05);
(void)signal(SIGINT,SIG_DFL);
}
int main(void)
{
(void) signal(SIGINT,mess);
printf("输入商品名:");
scanf("%s",&p1.str);
printf("输入价格:");
scanf("%lf",&p1.price);
while(1)
{
printf("press CTRL_C\n");
sleep(2);
}
return 0;
}
#include<signal.h>
#include<unistd.h>
struct product
{
char str[100];
double price;
};
struct product p1;
void mess(int sig)
{
printf("信号代号: %d\n",sig);
printf("商品名为: %s\n",p1.str);
printf("价格为: %.2lf\n",p1.price);
printf("含税价为: %.2lf\n",p1.price*1.05);
(void)signal(SIGINT,SIG_DFL);
}
int main(void)
{
(void) signal(SIGINT,mess);
printf("输入商品名:");
scanf("%s",&p1.str);
printf("输入价格:");
scanf("%lf",&p1.price);
while(1)
{
printf("press CTRL_C\n");
sleep(2);
}
return 0;
}