TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MARK HOOVER
from: KURT KUZBA
date: 1998-04-09 02:46:00
subject: reading input from stdin

MH> RS>   An array is base 0, meaning that the first subscript
MH> RS>   is 0.
MH>   Just out of curiosity.....is there anyway to set the
MH>   array base to base 1?  I have no intention of doing this,
MH>   but I know it can sometimes be done in other languages
MH>   such as Basic....
   Sure. You just need to use pointer math. I have an example of
   how this would be done, if I can find it... ( rummaging... )
   Ah! there it is. It's an interesting thing, actually. BASIC
   hides all its pointers and likely does something similar.
#include 
void *DIM(int first, int last, int var_size)
{
   char *temp = new char[var_size * (last - first + 1)];
   return (void*)temp;
}
int main(void)
{
   int loop, *test_array1 = (int*)DIM(1, 10, sizeof(int));
   int ta2[10], *test_array2 = ta2 - 1;
   for(loop = 1; loop <= 10; loop++)
   {
     test_array1[loop] = loop * 2;
     test_array2[loop] = loop * 3;
   }
   for(loop = 1; loop <= 10; loop++)
     cout << "Array1[" << loop << "] = " << test_array1[loop]
         << ",  Array2[" << loop << "] = " << test_array2[loop]
         << "\n" << flush;
   delete []&test_array1[1];
   return 0;
}
> ] ERROR: Demon not responding. Open pentagram to continue.....
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.