file1:
there are 20000000000000 Rows in file1.Code:12E3F 1E34F 34EF5 ......
Can I store the file into 20000000000000*5 array ?
if not , how to implement it ?
This is a discussion on how to store file of big size within the C Programming forums, part of the General Programming Boards category; file1: Code: 12E3F 1E34F 34EF5 ...... there are 20000000000000 Rows in file1. Can I store the file into 20000000000000*5 array ...
file1:
there are 20000000000000 Rows in file1.Code:12E3F 1E34F 34EF5 ......
Can I store the file into 20000000000000*5 array ?
if not , how to implement it ?
By 'store', I assume you mean 'load into memory all at the same time', which leads me to ask: Why?
To answer your question: No, you can't make a true array that size. You'll run out of stack space. Your best shot is to dynamically allocate it with something like malloc. But again, you're probably out of luck unless you're on a 64 bit OS. 100000000000000 is too big to fit in a 32bit data type.
Quzah.
Hope is the first step on the road to disappointment.
this is my test program . why error ?Code:#include "stdlib.h" #include "stdio.h" #include "string.h" int main(int argc,char *argv[]) { char **p = (char **) malloc ( 50*sizeof(char)); FILE *fr = fopen("test.data","r"); char a; int i = 0; int m = 0; int n = 0; while ( fscanf(fr, "%c", &a ) == 1 ) { //char line[10]; //fgets(line,10,fr); if ( a == '\n' ) { m = 0; n++; } else { *(*(p+n)+m) = a; m++; } } return 0; }
I have a feeling we've been over this before... take a look at your other threads again.
And no, you can't store a file that is 93 TB in memory. Not that I would ever see such a big file.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Why are you using a pointer to a pointer? If you want to pretend it's a 2D array, then you need two steps:You are using fscanf to read a single character. That's not its best suit. Why not just use fgetc if you only want one character?Code:char **p; p = malloc( sizeof( char * ) * numberofrows ); for( x = 0; x < numberofrows; x++ ) p[ x ] = malloc( numberofcolumnsperrow );
But to answer your question: it's crashing because you're not allocating memory right. See point one again.
Edit: And to go along with what Elysia said, stop making new threads for the same exact topic. You have like four now.
Quzah.
Hope is the first step on the road to disappointment.