如何解决将文件切成小块 (10)
我构建了一个服务器-客户端 UDP 系统,我需要从客户端向服务器发送一个文件(不知道文件的类型),但我需要以 10 个块为单位发送它每包位。 我不确定如何按字节读取文件,但我在网上找到了此代码:
FILE *fileptr;
char *buffer;
long filelen;
fileptr = fopen("myfile.jpg","rb"); // Open the file in binary mode
fseek(fileptr,SEEK_END); // Jump to the end of the file
filelen = ftell(fileptr); // Get the current byte offset in the file
rewind(fileptr); // Jump back to the beginning of the file
buffer = (char *)malloc(filelen * sizeof(char)); // Enough memory for the file
fread(buffer,filelen,1,fileptr); // Read in the entire file
fclose(fileptr); // Close the file
但我不确定如何“处理”文件的缓冲区,它是一个字符串数组,每个字符串都是一个字节吗?字节数组?我如何将它们分成 10 位的 chanks? 我试图打印缓冲区,但一无所获。
希望能帮到你。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。