gpt4 book ai didi

C编译IO错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:31:09 25 4
gpt4 key购买 nike

<分区>

我正在尝试将缓冲区的内容输出到文件,但出现无法破译的编译错误。有人可以澄清我做错了什么以及如何纠正它。谢谢。

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sdtio>

#define SERVER_PORT 4444
#define BUF_SIZE 4096
#define FILE *fptr

int main(int argc, char **argv)
{

fptr = fopen("TESTFILE.pdf", "wb");

int c, s, bytes;
char buf[BUF_SIZE];
struct hostent *h;
struct sockaddr_in channel;

if (argc != 3) fatal("Usage: client server-name file-name");
h = gethostbyname(argv[1]);
if (!h) fatal("gethostbyname failed");

s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0) fatal("socket");
memset(&channel, 0, sizeof(channel));
channel.sin_family= AF_INET;
memcpy(&channel.sin_addr.s_addr, h->h_addr, h->h_length);
channel.sin_port= htons(SERVER_PORT);
c = connect(s, (struct sockaddr *) &channel, sizeof(channel));
if (c < 0) fatal("connect failed");

write(s, argv[2], strlen(argv[2])+1);

while (1) {
bytes = read(s, buf, BUF_SIZE);
if (bytes <= 0) exit(0);
write(1, buf, bytes);
fputs(s,fptr);
}
fclose(fptr);
}

fatal(char *string)
{
printf("%s\n", string);
exit(1);
}

我得到的错误是:

p2Client2.c: In function âmainâ:
p2Client2.c:14: error: âfptrâ undeclared (first use in this function)
p2Client2.c:14: error: (Each undeclared identifier is reported only once
p2Client2.c:14: error: for each function it appears in.)

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