int counter = 0; int dest_pos = 20; for (int z = 0; z < 1000; z++) { /***2***/ if(counter++ == dest_pos) { /***1***/ //if reach dest position - than would set new value for dest_pos dest_pos = 56; } }
Memo1->Lines->Add(IntToStr(z));
int y = z;
IntToStr
z
for
#pragma once#include <stdio.h>#include <tchar.h>#include <malloc.h>static TCHAR __intBuff[64];#define IntToStr1(i) (const TCHAR*)__IntToStr1(i,__intBuff,sizeof(__intBuff)/sizeof(__intBuff[0]))#define IntToStr2(i) (const TCHAR*)__IntToStr2(i,__intBuff,sizeof(__intBuff)/sizeof(__intBuff[0]))const TCHAR* __IntToStr1(int& i,TCHAR* buff,const unsigned int blen){ _itot_s(i,buff,blen,10); i = 0;// <--- parameter 'i' may be lost or nulled by malfunction return buff;}const TCHAR* __IntToStr2(int& i,TCHAR* buff,const unsigned int blen){ i = 0;// <--- parameter 'i' may be lost or nulled by malfunction _itot_s(i,buff,blen,10); return buff;}int _tmain(int argc, _TCHAR* argv[]){ int counter = 0; int dest_pos = 20; _tprintf(__T("loop IntToStr1\r\n")); for (int z = 0; z < 1000; z++) { /***2***/ int y = z; /***3***/ if(counter++ == dest_pos) { /***1***/ _tprintf(__T("y = %s (OP says here comes z unchanged)\r\n"),IntToStr1(y)); _tprintf(__T("z = %s (OP says here comes 0)\r\n"),IntToStr1(z)); //if reach dest position - than would set new value for dest_pos dest_pos = 56; } } _tprintf(__T("loop IntToStr2\r\n")); counter = 0; dest_pos = 20; for (int z = 0; z < 1000; z++) { /***2***/ int y = z; /***3***/ if(counter++ == dest_pos) { /***1***/ _tprintf(__T("y = %s (OP says here comes z unchanged)\r\n"),IntToStr2(y)); _tprintf(__T("z = %s (OP says here comes 0)\r\n"),IntToStr2(z)); //if reach dest position - than would set new value for dest_pos dest_pos = 56; } } _tprintf(__T("<key> ")); _gettch(); return 0;}
loop IntToStr1y = 20 (OP says here comes z unchanged)z = 20 (OP says here comes 0)y = 36 (OP says here comes z unchanged)z = 36 (OP says here comes 0)loop IntToStr2y = 0 (OP says here comes z unchanged)z = 0 (OP says here comes 0)y = 0 (OP says here comes z unchanged)z = 0 (OP says here comes 0)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)