The thing is i don't want to scan the entered data to a temporary variable and then put it into the file
Why not?Is there any way to do so?
Nope. At some point during the process you'll be using memory.If not, what is the most efficient (memory-wise) way to get user's input into the file? char by char?
As far as memory footprint goes, character-by-character would be your best bet, but that implies a time trade-off. I honestly think you're going to an unnecessary extreme with this question. Maybe if you explained what you're trying to do and why, someone can offer a reasonable solution.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
No dinamic memory allocation at all.
There's nothing stopping you from using, for example, an array of char to read blocks from input with unknown length. This is what we did in C (usually for purposes of building a dynamic string, but you can write directly to file as well):
char buf[BLOCK_SIZE];
while (fgets(buf, sizeof buf, in) != 0) {
fputs(buf, out);
if (strchr(buf, '\n') != 0)
break;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401