The answer to this question is not so obvious, and understanding what happens implies understanding what you are doing.
First: a char variable holds a single byte , which for the Latin alphabet and arabic digits normally equals a single character - (but that depends on the encoding used.)
The variable you are using is a char[]
- this is a character pointer. What goes "in" to the variable itself is a memory address, which in normal PCs is usually an address of 8 bytes (64bit);
The number that goes between the brackets, as in char minhavariavel[1000]
, is an amount of bytes that the compiler leaves reserved in memory for its variable. The maximum value depends on the CPU architecture (for the first x86 16-bit PCs as well as the 8-bit machines, that number was 2 ^ 16 = 65536, for example). The maximum size for this depends on the structure of the program as it is defined by the compiler, and with the limit given by the operating system - on PCs with modern systems, one can think about 1MB for this. I just tested here, 5MB works, 10MB, the program crashes, on a 64bit Linux)
On a PC running a 64-bit OS, this number is limited by the compiler, because of the structure it uses to organize the program into memory, but if the memory is requested from the Operating System, at exercise time, the size of a char
vector can be as large as you like, with the computer memory limit. (Nm PC with 4GB, you separate a 300-400MB for the operating system and programs it uses, and could have a process using 3.6GB without sweating a lot.If you are manipulating text files, as it stands, roughly corresponds, to the text equivalent to 1000 bibles) -
But if you have a program that will work with this amount of data in memory it is generally worth using a dynamic memory allocation mechanism.
In short - no, there is no limit to the amount of bytes you can allocate to a vector of type char
, except the memory of your computer.
And the error you're having "not being able to read the file" is probably related to the error in the printf
call as I pointed out in the comment, just get the &
more.