我仍在为我的程序而苦苦挣扎,应该用符号打印字符 编译器说:
char参数与char *
类型不兼容
这是我的代码:
char characters[12] = {"ABCDEFGHIJ\0"};
char numbers[12] = {"0123456789\0"};
for (int vertical = 2; vertical<12; vertical++) {
for (int horizontal = 1; horizontal<2; horizontal++) {
text2(horizontal, vertical, numbers[horizontal]);
color2(horizontal, vertical, BLUE);
}
}
for (int abc = 170; abc < 180; abc++) {
color(abc, BLUE);
text(abc, characters[abc]);
}
实际上每次打印只能打印一个字符。 这里有两个功能
void color2(int i, int j, int f) {
sprintf_s(nachricht, ">># %d %d 0x%x\n", i, j, f);
sendMessage( nachricht );
void text2(int i, int j, char* f) {
sprintf_s(nachricht, ">>#T %d %d %s\n", i, j, f);
sendMessage( nachricht );
}
color2颜色字段和text2显示字段上的字符 这是函数sendMessage的代码,它包含在两个提到的函数中
int sendMessage(char *sendbuf ) {
WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
struct addrinfo *result = NULL,
*ptr = NULL,
hints;
int iResult;
int recvbuflen = DEFAULT_BUFLEN;
char recvbuf[DEFAULT_BUFLEN];
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed with error: %d\n", iResult);
return 1;
}
ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
// Resolve the server address and port
iResult = getaddrinfo("localhost", DEFAULT_PORT, &hints, &result);
if ( iResult != 0 ) {
printf("getaddrinfo failed with error: %d\n", iResult);
WSACleanup();
return 1;
}
// Attempt to connect to an address until one succeeds
for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) {
// Create a SOCKET for connecting to server
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype,
ptr->ai_protocol);
if (ConnectSocket == INVALID_SOCKET) {
printf("socket failed with error: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
// Connect to server.
iResult = connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
if (iResult == SOCKET_ERROR) {
closesocket(ConnectSocket);
ConnectSocket = INVALID_SOCKET;
continue;
}
if( verbose ) printf("socket connected\n");
break;
}
freeaddrinfo(result);
if (ConnectSocket == INVALID_SOCKET) {
terminate("Unable to connect to server!\n");
}
// Send an initial buffer
iResult = send( ConnectSocket, sendbuf, (int)strlen(sendbuf), 0 );
if (iResult == SOCKET_ERROR) {
printf("send failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
if( verbose ) printf("Bytes Sent: %ld\n", iResult);
// shutdown the connection since no more data will be sent
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
printf("shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
answer[0] = '\0';
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 ) {
recvbuf[iResult] = '\0';
if( verbose ) printf("Bytes received: %d %s\n", iResult, recvbuf);
strcat_s( answer, recvbuf );
//printf(">>>%s<<<\n", answer );
} else if ( iResult == 0 ) {
if( verbose ) printf("Connection closed\n");
} else
printf("recv failed with error: %d\n", WSAGetLastError());
} while( iResult > 0 );
// cleanup
closesocket(ConnectSocket);
WSACleanup();
return 0;
}
答案 0 :(得分:1)
您需要取消引用指针。可能是在你调用的函数之一中,可能是在text2()或text()中。如果不了解更多关于功能的规格,就无法告诉你更多信息。