The answer to this question is not so obvious, and understanding what happens implies understanding what you are doing.
First: a variable of type "char" behaves a single byte, that for the Latin alphabet and Arabic digits, usually equates to a single character - (but this depends on the coding used.)
The variable you are using is a char[]
- That’s a character pointer. What goes "inside" of 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 a number of bytes that the compiler leaves in memory for its variable. The maximum value depends on the CPU architecture (on the first 16bit x86 PC as well as on the 8-bit machines, this number was 2 16 = 65536, for example). The maximum size for this depends on the structure of the program as defined by the compiler, and with the limit given by the operating system - on Pcs with modern systems, one can think of around 1MB for this. I just tested here, 5MB works, 10MB, the program fails, on a 64bit Linux)
On a PC running a 64-bit S.O. this number is limited by the compiler, because of the structure it uses to organize the program in memory, but if the memory is requested from the Operating System, at exercution time, the size of a vector of char
can be as big as you want 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 too much. If you are manipulating text files, as it is, roughly corresponds to the text equivalent to 1000 bibles) -
But if you have a program that will work with that amount of data in memory in general it is worth using a dynamic memory allocation mechanism.
In short - no, there is no limit to the amount of bytes you can allocate to a type vector char
, except the memory of your computer.
And the error you are experiencing of "unable to read file", is probably related to the error in calling printf
as I pointed out in the comment is just take the &
the most.
I don’t know if I understand the question, you can try to make it clearer. I don’t see any doubt, just affirmation or obviousness (for me).
– Maniero
My question, is whether it has any maximum amount, that a char type variable supports of caraceteres.
– Paulo Sergio G.M. Filho
Because the program is not reading the . txt file
– Paulo Sergio G.M. Filho
printf("%s", &pagina1);
take that one off&
hence - let aloneprintf("%s", pagina1);
– jsbueno
Leu normal correcting pointer to be displayed: https://repl.it/@acwoss/Earlyrashcustomer
– Woss
Really put the '&' accidentally.
– Paulo Sergio G.M. Filho