如何解决带有 C 的消息队列传递 2 个数字和 1 个运算符,但在服务器文件中出错
在消息队列中,我创建了 server.c 和 client.c。创建了一个包含 2 个数字的结构,1 个字符用于操作员,1 个字符用于消息类型。 程序即将向服务器发送两个数字和一个运算符,服务器执行该程序并将该表达式的答案发送回客户端。
但我不断收到以下错误
已删除标识符
我不知道我哪里做错了。
header.h
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
client.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/types.h>
`
server.c
#include "./header.h"
#define KEY 777
#define SIZE 50
struct message
{
long type;
double no1,no2;
char operator;
char ans[SIZE];
};
int main()
{
struct message msg;
int qid = msgget((key_t)KEY,IPC_CREAT | 0666);
if (qid < 0)
perror("Error creating queue");
else
{
printf("Enter no1 : ");
scanf("%lf",&msg.no1);
printf("Enter no2 : ");
scanf("%lf",&msg.no2);
getc(stdin);
printf("Enter operator : ");
msg.operator= getchar();
msg.type = 1;
if (msgsnd(qid,&msg,sizeof(msg) - sizeof(msg.type),IPC_NowAIT) < 0)
perror("Error to write data");
else
{
// if (msgrcv(qid,sizeof(msg.ans),2,0) < 0)
// perror("error to read response");
// else
// {
// printf("%s\n",msg.ans);
// }
}
msgctl(qid,IPC_RMID,NULL);
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。