Intializing Large Character Array [Solved]

Posts 115 of 27 · Page 1 of 2
Intializing Large Character Array [Solved]
I need help creating a long char array. Or is there a much simpler way to do this? I dont want to type it out to 30000. Is there a much shorter way to do this?

char *num[] = { "1", "2", .., "29000", "30000" };
Utilize a for loop? :/ Unless this is a static array then I have no idea.
Code:
char *largeArray[30000];
for(int i = 0;  i < 30000; i++)
    largeArray[i] = itoa(i + 1)
There you go.
Quote Originally Posted by Jason View Post
Code:
char *largeArray[30000];
for(int i = 0;  i < 30000; i++)
    largeArray[i] = itoa(i + 1)
There you go.
'itoa' : function does not take 1 arguments
Quote Originally Posted by Braco22 View Post
'itoa' : function does not take 1 arguments
You do realize that chars only go to 255 right? so once you go over that magic number behavior will be undefined?
Quote Originally Posted by .::SCHiM::. View Post
You do realize that chars only go to 255 right? so once you go over that magic number behavior will be undefined?
char *values[0xFF]

Is a double pointer, so essentially an array of char* or an array of strings, not an array of chars.
Quote Originally Posted by Jason View Post


char *values[0xFF]

Is a double pointer, so essentially an array of char* or an array of strings, not an array of chars.
Ohh wait, you're right missed the '*' there, I've said nothing
oh yeh that's right.

largeArray[i] = itoa(i + 1, new char[10], 10);
/Marked Solved.
To save on 30,000 memory allocations:

Code:
char buffer[10];
char *values[30000];
for ( int i = 0; i < 30000; i++ )
    values[i] = itoa(i + 1, buffer, 10);
Quote Originally Posted by Jason View Post
To save on 30,000 memory allocations:

Code:
char buffer[10];
char *values[30000];
for ( int i = 0; i < 30000; i++ )
    values[i] = itoa(i + 1, buffer, 10);
you cant NOT have 30000 memory allocations unless you use static char arrays. your solution would have 30000 char*s all pointing to "30000".

Code:
char* OP[30000];
for (int Doesnt = 0; Doesnt < 30000; ++Doesnt)
{
	char* KnowCPP = new char[15];
	_itoa(Doesnt, KnowCPP, 10);
	OP[Doesnt] = KnowCPP;
}
When i was first learning c++ i really hated pointers and i thought they were so useless. Now that i understand pointers i have discovered that they are really helpful. And this thread is another example of this.


(I know this doesn't have anything to do with the thread, but i just posted it so the newbies at c++ know that pointers are extremely important)
I thought everyone knew pointers were important lul.
Quote Originally Posted by Jason View Post
I thought everyone knew pointers were important lul.
Well, people who are like me 8 months ago don't know. Trust me, 8 months ago 4 months after starting c++ i really thought that i would never have to use pointers because they are stupid and pointless(no pun intended). LOL.
Lol but how would you survive without char*? I've only been C/C++'ing for 4 weeks at uni and basic pointers was one of the first things we learned.
Posts 115 of 27 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?