gpt4 book ai didi

c - 对 _red 的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 14:23:20 25 4
gpt4 key购买 nike

我正在编写一个简单的客户端程序“套接字编程”,当使用 cygwin 编译代码时,我收到此错误“对'_red'的 undefined reference ” 代码如下。我一直用这个语句编译gcc client.c我真的不明白为什么我会收到这个错误。我真的需要一些帮助。代码如下。

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdlib.h>
#include <strings.h>
#include <netinet/in.h>

#define SERVER_TCP_PORT 2000
#define BUFLEN 256

int main(int argc,char **argv)
{
int n,bytes_to_read;
int sd,port;
struct hostent *hp;
struct sockaddr_in server;
char *host,*bp,rbuf[BUFLEN],sbuf[BUFLEN];
switch(argc) {
case 2:
host = argv[1];
port = atoi(argv[2]);
break;
default:
fprintf(stderr,"Usage: %s host[port] \n",argv[0]);
exit(1);
}
/*Create a streamm socket*/
if ((sd=socket(AF_INET,SOCK_STREAM,0))==-1){
fprintf(stderr,"Can't create a socket\n");
exit(1);
}
bzero ((char *)&server,sizeof(struct sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(port);
if((hp = gethostbyname(host))==NULL){
fprintf (stderr,"Can't get server's address\n");
exit(1);
}
//bcopy(hp->h_addr,(char *)&server.sin_addr,hp->h_length);
/*connecting to the server*/
if (connect (sd,(struct sockaddr *)&server,sizeof(server))==-1){
fprintf(stderr,"Can't connect \n");
exit(1);
}
printf("Connected:server's address is %s\n",hp->h_name);
printf("Transmit: \n");
gets(sbuf); /*get user's text*/
write (sd,sbuf,BUFLEN); /*send it out*/
printf("Receive: \n");
bp = rbuf;
bytes_to_read = BUFLEN;
while ((n=red(sd,bp,bytes_to_read))>0){
bp+=n;
bytes_to_read -=n;
}
printf("%s\n",rbuf);
close(sd);
return(0);
}

最佳答案

上线

while ((n=red(sd,bp,bytes_to_read))>0){

它是红色的,你可能是说已读

关于c - 对 _red 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12962464/

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