You may use either the legacy rand()[^] function (with the srand one you might provide the seed), or the classes provided by the 'new' random header[^]. The latter is more sophisticated and has a somewhat more difficult interface. You might look at code samples, though, for instance, see the code in this page[^].
Using return where you do, exits the current function you are in, in this case it is main(). So you are exiting the program when you call return.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
This is something I hate, but it's idiomatic. A C string ends with the character NUL, whose ASCII value is 0, which is equivalent to false. So the loop ends when the character NUL (usually written as '\0') is encountered. The check is equivalent to
name[i] != '\0'
but some people hate typing so much that they write this kind of thing.
The for statement breaks down as three individual expressions:
for(set; while; do) :
// set : perform this or these expressions first: multiple expressions must be separated by commas
// while : repeat the loop while this expression equates to true
// do : perform this or these expressions at the end of each loop
Note that any of these expressions (or indeed all of them) may be blank.
In your code the expression in the while part is name[i], which means while name[i] is true, or rather while name[i] is not equal to zero. Strings in C are (or should be) terminated with a zero character (NULL), so the expression will be true as long as the character in question is not the terminating NULL.
Sure, as a pointer to that element (&array[i]) or as a reference (array[i]). This is assuming you want access to the actual element, not a copy. If it's an array of int, the receiving arguments would have the types int* and int&, respectively.
No, this only gives you access to the element that you pass in. If you want access to all of them, pass the array itself (I seem to remember a previous thread about how to do that) and use the index operator.
With a typical client/server application, your TCP server runs on the remote machine, waiting for 'gimme next line' command from the client. On command reception, it reads the line and answers to the client with the read line content.
Last Visit: 31-Dec-99 18:00 Last Update: 28-Jun-22 5:04