Hello! I’m trying to copy a picture byte-by-bye, almost it turns out ... In the output image file, an offset occurs ... Well, bytes 00 00 cc aa ss go, and at the output 00 is added somewhere and 00 00 00 cs aa cc is obtained. Where does he come from? I put checkpoints in the character buffer, everything seems to be correctly entered ...

Here is a piece of code:

unsigned char ch[1000000]; int hight, wight; FILE *stream,*stream3; stream = fopen("w.bmp", "rb"); stream3 = fopen("file2.bmp","w"); if ((stream==NULL)||(stream3==NULL)){ cout << "Can't open file!\n"; } int i=0; while(!feof(stream)){ //putc(ch[i]=getc(stream),stream3); ch[i]=getc(stream);//В массив всё!!! i++; } i-=2;//Всё верно!!! int counter=i; fseek(stream3,0,SEEK_SET);// в начало файла//54-начало файла ставим 0 int y=0; while(y<=counter){ putc(ch[y],stream3);//Вроде как не работает... y++; } Вод фрагмент из winhex: do: posle 38 c4 38 00 39 ab 39 c4 40 .. 40 ab 

And another thing, the studio sometimes said stakc overflow ... What is this error ???

  • one
    Google will help you. - nitrocaster

2 answers 2

stakc overflow

unsigned char ch [1000000];

Well, not surprising. Read about dynamic memory.

  • Can't a static array of this size be made? - Alerr
  • You can teach the hare to smoke (C). Static - try, but first learn to distinguish static from automatic variables that are created on the stack ... - user6550
  • I know how to work with dynamically allocated memory (arrays), I wonder why there is a stack overflow? I know little about subtleties ... Does the application have a limited (non-expandable memory) at startup? If so, how can you increase it? On the net, such subtleties are not particularly spoken about ... in any case, I have not met ... - Alerr
  • Because a stack is allocated a piece of memory that is larger than the size of the stack. Your Captain Obvious. > If so, how can you increase it? Increase stack size (see compiler settings). Once, as an experiment, after which forget about such nonsense once and for all. - user6550
  • You allocate a million bytes on the stack, and wonder why there is an overflow? No, you still read about automatic variables, these are not subtleties, they are the basics. - VladD

The first link in Yandex

Despite the curve, the translation is quite readable.