读取大文件 ~335GB 时 fread() 失败并出现此错误。感谢任何有关如何解决此问题的建议。
opt$input_file <- "sample-009_T/per_read_modified_base_calls.txt"
Error in data.table::fread(opt$input_file, nThread = 16) :
long vectors not supported yet: ../../src/include/Rinlinedfuns.h:537
Execution halted
Run Code Online (Sandbox Code Playgroud)
文件大小和片段
(base) bash-4.2$ ls -thl per_read_modified_base_calls.txt
-rw-r--r-- 1 lih7 user 335G May 31 15:24 per_read_modified_base_calls.txt
(base) bash-4.2$ head per_read_modified_base_calls.txt
read_id chrm strand pos mod_log_prob can_log_prob mod_base
d1c2a9e7-8655-4393-8ab1-c1fa47b0dc5c chr12 + 94372964 -8.814943313598633 -8.695793370588385 h
d1c2a9e7-8655-4393-8ab1-c1fa47b0dc5c chr12 + 94372964 -0.00031583529198542237 -8.695793370588385 m
2109b127-c835-47f3-b215-c238438829b6 chr10 - 118929450 -3.0660934448242188 -5.948376270726361 h
2109b127-c835-47f3-b215-c238438829b6 chr10 - 118929450 -0.05046514421701431 -5.948376270726361 m
2109b127-c835-47f3-b215-c238438829b6 chr10 - …Run Code Online (Sandbox Code Playgroud) 我有一个文件.我读了文件的大小.然后我一次循环读取两个字节,直到我到达文件的末尾.在每次读取操作之后,我将当前位置递增2,但是在达到文件大小的一半后位置不会增加,fread操作将读取0个字节.
程序读取文件大小.我执行fread(每次2个字节),直到当前位置等于文件的大小.对于文件大小,它读取22915个字节.每次读取后,它将位置增加2,但是当当前位置达到11459时,它是文件大小的一半,因此将读取零字节,从而进入无限循环.
FILE *file;
char *file_name;
int readCount = 0;
int position = 0;
int fileSize;
unsigned short mem_accesses;
file_name = "sample.txt";
/** open the file */
file = fopen(file_name, "rb");
fseek(file, 0, SEEK_END);
fileSize = ftell(file);
rewind(file);
while(position<fileSize){
mem_accesses = getNumberAccesses();
printf("position: %d filesize: %d\n",position, fileSize);
}
unsigned short getNumberAccesses(){
/** calculate number of accesses for process */
unsigned short val;
readCount = fread(&val, sizeof(val), 2, file);
position += readCount;
printf("read count: %d\n", readCount);
return val;
}
Run Code Online (Sandbox Code Playgroud) 我可以假设使用fwrite生成的文件和使用fread读取的文件可以跨不同系统移植.32位/ 64位Windows,osx,linux.
//dumping
FILE *of =fopen("dumped.bin","w");
double *var=new double[10];
fwrite(var, sizeof(double), 10,FILE);
//reading
file *fo=fopen()
double *var=new double[10];
fread(var,sizeof(double),10,of);
Run Code Online (Sandbox Code Playgroud)
结构怎么样?
struct mat_t{
size_t x;
size_t y;
double **matrix;
}
Run Code Online (Sandbox Code Playgroud)
这些便携式吗?
各种用户正在浏览100%用C(CGI)编程的网站.每个网页都使用fopen/fgets/fread从文件中读取常用数据(如导航栏).如果各种各样的人浏览同一页面,每次打电话给fopen/fgets/fread会互相干扰吗?如果是这样,如何在C中解决?(这是一个Linux服务器,编译是用gcc完成的,这是用C编程的CGI网站.)
例:
FILE *DATAFILE = fopen(PATH, "r");
if ( DATAFILE != NULL )
{
while ( fgets( LINE, BUFFER, DATAFILE ) )
{
/* do something */
}
}
Run Code Online (Sandbox Code Playgroud) 为什么我的filesize()方法不起作用?我的路径适用于fread()和file()方法,但它不会承认路径filesize().为什么不?我的正确道路应该是什么?
<?php
$strLessonDescription = fopen("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/lesson5.txt", "r")
or die ("Error - lesson5.txt cannot be opened");
$lessonDescription = fread($strLessonDescription,
filesize("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt"));
fclose($strLessonDescription);
echo $lessonDescription;
$arrLessonVocabulary = array();
$arrLessonVocabulary = file("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt");
if (arrLessonVocabulary == NULL)
print "Error - vocabulary5.txt cannot be opened";
?>
Run Code Online (Sandbox Code Playgroud) 我目前正在忙于一个项目,我必须将一个部分从一个文件复制到另一个文件,所以我使用fread和fwrite为它创建了一个代码.但我遇到了一个问题:出于测试目的,我制作了一个应该复制整个文件的代码,但不知何故,代码创建的副本比原始文件大.请参阅下面的代码
FILE *base_file;
FILE *new_file;
fpos_t curpos;
int tmp;
// Open the base file
fopen_s(&base_file, "C:/base.dat", "rb");
// Open the file which should contain the copy
fopen_s(&new_file, "C:/new.dat", "w");
// Get the filesize
fseek(base_file, 0, SEEK_END);
fgetpos(base_file, &curpos);
fseek(base_file, 0, SEEK_SET);
//Read and copy (it seems to go wrong here)
for(int i = 0; i < curpos; i++){
fread (&tmp, 1, 1, base_file);
fwrite(&tmp, 1, 1, new_file);
}
fclose(base_file);
fclose(new_file);
Run Code Online (Sandbox Code Playgroud)
基本文件为525 kb,新文件为527kb.据我所知,出现此问题的部分是在有7个nullbytes的部分之后,并且副本在某些部分之后添加了一个'0D'(十六进制).在ascii中,'0D'字符是'回车'.我想知道我的复制代码将回车符添加到文件中的原因是什么?据我所知,这个脚本应该只是工作,因为我只是读取基本文件,并直接将其复制到新文件,并且基本文件不包含这些回车.
我即将阅读一个200Mb的文本文件,然后在里面编辑一些东西,然后将其保存回来.但我有错误.所以:
另外哪种文件读取方法最适合打开和解析Big Sized文件?我的意思是:
尝试创建1024字节随机数据的文件.当我运行它时,我在fread线上出现了分段错误错误.有谁看到我做错了什么?谢谢!
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#define PERMS 0666
int main() {
char buf[1024];
if (creat("test.txt", PERMS) < 0) {
fprintf(stderr, "couldn't create file\n");
exit(0);
}
char randomData[1024];
FILE* fp;
fp = (void*) open("/dev/urandom", O_RDONLY, PERMS);
fprintf(stderr, "here\n");
fread(&randomData, 1024, 1, fp);
fclose(fp);
return 0;
}
Run Code Online (Sandbox Code Playgroud) /*Write a program that indefinitely takes in files to append to a master
file. If the file names are the same, don't do it. If there's an error,
don't do it. Exit with a blank line. Use a custom buffer.*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME 25
#define BUFSIZE 1024
int append(FILE *, FILE *);
int main(){
char src[MAX_NAME], mainfile[MAX_NAME];
FILE *src_ptr, *mainfile_ptr;
int successes = 0;
puts("Enter name of main file");
if(gets(mainfile) == NULL){
fprintf(stderr, "Error, couldn't …Run Code Online (Sandbox Code Playgroud) 我是一名新的程序员,现在我已经开始使用c了.我正在尝试解码IDEv3 mp3标签,我遇到了各种各样的问题.当我使用fread()和strncpy()命令时,我注意到两者都需要将\n字符作为结束参考点.(也许我错了,这只是观察)
当我打印输出时,它们产生一个不可读的字符.作为解决问题的解决方案我使用fread()4字节而不是3字节来生成(8)\n字符(整个字节),第二步我使用strncpy()和3字节分配给分配然后我用于打印的记忆.理论上,当我使用fread()时,我不应该遇到这个问题.
代码示例:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
unsigned char header_id[3]; /* Unsigned character 3 Bytes (24 bits) */
}mp3_Header;
int main (int argc, char *argv[]) {
mp3_Header first;
unsigned char memory[4];
FILE *file = fopen( name.mp3 , "rb" );
if ( (size_t) fread( (void *) memory , (size_t) 4 , (size_t) 1 , (FILE *) file) !=1 ) {
printf("Could not read the file\n");
exit (0);
} /* End of if condition */
strncpy( (char *) first.header_id …Run Code Online (Sandbox Code Playgroud)