gpt4 book ai didi

c - C 程序中常量错误之前缺少语法错误

转载 作者:行者123 更新时间:2023-11-30 17:43:03 27 4
gpt4 key购买 nike

#include "MAIN.h"
#define port 444 //port number
//port = 18017;

typedef unsigned _int8 uint8;
typedef unsigned _int16 uint16;
typedef unsigned _int32 uint32;

uint32 measurements[18];


void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16);

void main(void)
{

#ifdef XCP_ENABLE
/*initialise the XCP Ecu Softwares */

Xcp_Initialize();

#endif
//initialize before start of the operating system

while(1)
{
Timer1();
Timer2();
Timer3();
}
}

/此行错误/void XcpApp_IpTransmit(uint16 port, Xcp_StatePtr8 pBytes, uint16 numBytes)//此函数必须在端口标识的 IP 连接上传输指定字节 {

        pBytes = &measurements;     // pBytes points to address of the memory
numBytes = 8; //number of bytes at pBytes.

struct sockaddr_in server; // creating a socket address structure: structure contains ip address and port number
WSADATA wsa;
SOCKET s;
int len;
//int bytes_recieved;
//char send_data[1024],recv_data[1024];

printf("Initializing Winsock\n");
if(WSAStartup(MAKEWORD(2,2), &wsa)!=0)
{
printf("Failed Error Code: %d", WSAGetLastError());
return 1;
}
printf("Initialised\n");


//CREATING a SOCKET

if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Could not Create Socket\n");
return 0;
}
printf("Socket Created\n");

server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_family = AF_INET;
server.sin_port = htons("port");
len = sizeof(server);

//SENDING a data

/* bzero(&(server_addr.sin_zero),8);

if (connect(sock, (struct sockaddr *)&server_addr,
sizeof(struct sockaddr)) == -1)
{
perror("Connect");
exit(1);
}*/

while(1)
{

//bytes_recieved=recv(s,recv_data,1024,0)

numBytes=recvfrom(s, pBytes, 8, 0, (struct sockaddr*)&server, &len);
pBytes[numBytes] = '\0';

if (strcmp(pBytes , "q") == 0 || strcmp(pBytes , "Q") == 0)
{
close(s);
break;
}

/* else
printf("\nreceived data = %s " , pBytes);*/
// XcpIp_RxCallback (chunkLen, pChunkData, port);

/*
printf("\nSEND (q or Q to quit) : ");
gets(send_data);

if (strcmp(send_data , "q") != 0 && strcmp(send_data , "Q") != 0)
send(s,send_data,strlen(send_data), 0); */

else
{
//after the data has ben transmitted
XcpIp_TxCallback (port, numTxBytes);
//send(s,send_data,strlen(send_data), 0);
closesocket(s);
WSACleanup();
break;
}
}


}

我创建了一个18*4字节的内存,指定了端口号,然后我调用一个函数 void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16); 将数据从内存传输到指定端口号。我正在主函数中执行一些任务。后面的函数定义是为被调用的函数编写的(创建套接字并通过端口号和IP地址发送数据)我收到这样的错误:

error C2143: syntax error : missing ')' before 'constant'
error C2143: syntax error : missing '{' before 'constant'
error C2059: syntax error : '<Unknown>'
error C2059: syntax error : ')'

有人可以帮我修复这个错误吗(错误位于函数 void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16) 的主体中)??????

最佳答案

如果这是一个 C 程序,我看到的第一个错误是函数 XcpApp_IpTransmit() 中的变量声明不是其作用域的第一行。

换句话说,尝试将该函数的前几行更改为以下内容:

void XcpApp_IpTransmit(uint16 port, Xcp_StatePtr8 pBytes, uint16 numBytes) // this function must transmit the specified byte on IP connection identified by port
{
struct sockaddr_in server; // creating a socket address structure: structure contains ip address and port number
WSADATA wsa;
SOCKET s;
int len;
//int bytes_recieved;
//char send_data[1024],recv_data[1024];

pBytes = &measurements; // pBytes points to address of the memory
numBytes = 8; //number of bytes at pBytes.

printf("Initializing Winsock\n");
...
}

关于c - C 程序中常量错误之前缺少语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323823/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com