The purpose of this thread is to share with NeoSource users 'some' notes about what I learn from C++ coding, and discus different point of views (with those who like to participate here).
btw, I will not post rated material, so I assume that the reader know at least a little about C++, if you don't understand something please let me know so I can help you too
. Everything here is written by me and if I use coding from another site I will let it know very clear where it comes from.
I will start with something useful when declaring variables of different types...
:: Making life easier with ArraysWhen declaring variables you have various alternatives, for example, you have 10 documents and you plan to save the document titles into different variables for use later in some part of your application / program, well in that case you can simply do this two things to declare variables :
char Document_01[64] = "Die Hard I";
char Document_02[64] = "The Butterfly";
char Document_03[64] = "Rocketman";
char Document_04[64] = "Predator";
char Document_05[64] = "Believe it or Not";
char Document_06[64] = "I love my Pizza";
char Document_07[64] = "Pictures of Animals";
char Document_08[64] = "Zelda";
char Document_09[64] = "XXX";
char Document_10[64] = "NeoSource for Dummies";
...or, OK the is still one more ''simple'' way to put this stuff...
char Document_01[64] = "Die Hard I", Document_02[64] = "The Butterfly", Document_03[64] = "Rocketman", Document_04[64] = "Predator", Document_05[64] = "Believe it or Not", Document_06[64] = "I love my Pizza", Document_07[64] = "Pictures of Animals", Document_08[64] = "Zelda", Document_09[64] = "XXX", Document_10[64] = "NeoSource for Dummies";
Man, ...that coding looks nasty
, lets bring Arrays right now to our application before this convert into a war zone
. Ok, so I will describe arrays in my own way, they are very similar to normal variables but with only one declaration you can save looooot of typing, why?, well it stores data values into different elements, you can specify how much elements it will have like this (lets use 10 elements for our 10 document titles):
char Document[10][64] = { {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""} };
So now that you know that, I will make the same thing as the previous examples BUT with just an Array
:
char Document[10][64] = { {"Die Hard I"}, {"The Butterfly"}, {"Rocketman"}, {"Predator"}, {"Believe it or Not"}, {"I love my Pizza"}, {"Pictures of Animals"}, {"Zelda"}, {"XXX"}, {"NeoSource for Dummies"} };
The titles of the documents are obtained by simply adding the values directly into the array right now, but I will show you how we can get them from another array that could be declared in other place and with more data different than the last one, in that case we just handle the array contents specifying the element number, check it out:
We have the titles coming from an array called 'Title' that have 10 elements.
char Title[10][64] = {
{"Die Hard I"},
{"The Butterfly"},
{"Rocketman"},
{"Predator"},
{"Believe it or Not"},
{"I love my Pizza"},
{"Pictures of Animals"},
{"Zelda"},
{"XXX"},
{"NeoSource for Dummies"}
};
Now I will use a loop to copy all the titles to the 'Document' array without writing the 'Title[1], Title[2], Title[3], etc...':
for( int nElement = 0; nElement < 10; nElement++) {
strcpy( Document[nElement], Title[nElement] );
}
That loop is not posible when using individual variables for each document title and requires a long switch (of course if we have the titles coming from an array):
for( int nElement = 0; nElement < 10; nElement++) {
switch(nElement)
{
case 1:
strcpy( Document_01, Title[nElement] );
break;
case 2:
strcpy( Document_02, Title[nElement] );
break;
case 3:
strcpy( Document_03, Title[nElement] );
break;
case 4:
strcpy( Document_04, Title[nElement] );
break;
case 5:
strcpy( Document_05, Title[nElement] );
break;
case 6:
strcpy( Document_06, Title[nElement] );
break;
case 7:
strcpy( Document_07, Title[nElement] );
break;
case 8:
strcpy( Document_08, Title[nElement] );
break;
case 9:
strcpy( Document_09, Title[nElement] );
break;
case 10:
strcpy( Document_10, Title[nElement] );
break;
}
}
So that ends my C++ Learning notes for today ^^, if you have anything to comment or share Ill be happy to read ^^
I attached a example .cpp file that can be compiled to test what I was doing here
(If you have Visual Studio you can compile it from the Visual Studio command prompt located on Tools, write 'c:\***yourpath***\cl easyarrays_01.cpp' and press enter)
SeeYaa!