Search Results

Showing results 1 to 40 of 681
Search took 0.04 seconds.
Search: Posts Made By: Tom Gunn
Forum: C 20 Days Ago
Replies: 8
Views: 487
Posted By Tom Gunn
Assuming it is always 3 numbers, and what you want is the median value, here is a simple way. Find the maximum then the minimum and the one you didn't pick is the median. :)
Forum: C 20 Days Ago
Replies: 2
Views: 279
Posted By Tom Gunn
You do need to do an fseek to that location, but not because C uses separate read and write pointers. The standard says that when switching between read and write mode on a stream, there needs to be...
Forum: C 20 Days Ago
Replies: 3
Views: 313
Posted By Tom Gunn
Typically the two options for a case like this are a count argument and a sentinel argument:

#include <stdio.h>
#include <stdarg.h>

/* gets a count of arguments */
void TestCount(int x, int...
Forum: DaniWeb Community Feedback 21 Days Ago
Replies: 2
Views: 485
Posted By Tom Gunn
I can go to the Delphi forum, then under the Related Forum Features box on the right there is a direct link to all Delphi snippets.
Forum: C 23 Days Ago
Replies: 4
Views: 192
Posted By Tom Gunn
No. That is the nature of undefined behavior, it is unpredictable. We can only speculate about what will happen and hope that it happens consistently.
Forum: C 24 Days Ago
Replies: 4
Views: 192
Posted By Tom Gunn
Undefined. In practice it will probably print whatever is next in the stack and potentially corrupt the rest of your program by moving the stack pointer in an unexpected way.
Forum: C++ 24 Days Ago
Replies: 3
Views: 188
Posted By Tom Gunn
Do not write the line in the first place and you do not have to delete it. :)
Forum: C 27 Days Ago
Replies: 5
Views: 239
Posted By Tom Gunn
Not legally, AFAIK. Any that you find are pirated and in breach of copyright. You can contact Addison-Wesley and ask them to be sure, but I think you will get the same answer.
Forum: C++ 28 Days Ago
Replies: 1
Views: 214
Posted By Tom Gunn
C++ has two kinds of strings. The strings inherited from C are char arrays with a terminating '\0' character. All of the rules for arrays apply, which means you can only return a pointer to the array...
Forum: C++ 34 Days Ago
Replies: 10
Views: 699
Posted By Tom Gunn
Not at all. The generator is seeded by default to a value of 1. It does not make the sequence returned by rand() any less random. The sequence is deterministic based on the seed, so every time the...
Forum: C++ Oct 30th, 2009
Replies: 5
Views: 218
Posted By Tom Gunn
Yes, but only if the condition is available at compile time. In your case the value of i is a run time quantity, so you cannot use it with the preprocessor. I think what you really want is an if...
Forum: C++ Oct 30th, 2009
Replies: 10
Views: 699
Posted By Tom Gunn
Why would I bother? It is an example program meant to show how the range of rand() can be shifted using modulus. Adding unnecessary code will only muddy the waters.
Forum: C++ Oct 30th, 2009
Replies: 10
Views: 699
Posted By Tom Gunn
You presume that seeding is a required step, which it is not. Design choices are not the same as memory lapses. ;)
Forum: C++ Oct 29th, 2009
Replies: 10
Views: 699
Posted By Tom Gunn
The simplest way to adjust the range of rand() is with the modulus operator:

#include <iostream>
#include <cstdlib>

int main()
{
for (int x = 0; x < 20; ++x)
{
std::cout <<...
Forum: C++ Oct 29th, 2009
Replies: 5
Views: 270
Posted By Tom Gunn
I would put it in a separate constructor, as well as a public method. The actual implementation could be in a private method that is shared between the two.


Well... That is really up to your...
Forum: C++ Oct 29th, 2009
Replies: 7
Views: 358
Posted By Tom Gunn
That sounds like you need to skip leading whitespace at the token level. When resetting start, instead of incrementing it, walk it over all whitespace. The following is a stream of consciousness. It...
Forum: C Oct 29th, 2009
Replies: 5
Views: 309
Posted By Tom Gunn
These wants do not jive. If you use fgets() alone, you have no choice but to provide a buffer large enough to hold the maximum expected line length. If you use sscanf() to extract a word, you have no...
Forum: C Oct 29th, 2009
Replies: 2
Views: 358
Posted By Tom Gunn
The second menu is legitimate. When you typed something for scanf() to read, you also pressed [Enter], right? That [Enter] is a character too, and it is stored in the stream as '\n'. The first menu...
Forum: C++ Oct 29th, 2009
Replies: 2
Views: 228
Posted By Tom Gunn
You can learn on your own how to do it and not have to wait for your class to catch up. Then again, patience is an important trait for a programmer to have. Rushing through something because you are...
Forum: C Oct 29th, 2009
Replies: 6
Views: 326
Posted By Tom Gunn
It is done by the C runtime. The same code that calls main() collects arguments from the command shell and parses them into an array of char pointers.
Forum: C++ Oct 28th, 2009
Replies: 2
Views: 261
Posted By Tom Gunn
Does your AvlNode class have a public default constructor, public destructor, and public assignment operator? Those are the requirements for storage in a container class.
Forum: C++ Oct 28th, 2009
Replies: 8
Views: 355
Posted By Tom Gunn
It does not, as you proved. I did not consider adjacent punctuation in my haste to get my post out the door and ended up over engineering the whole thing. Since punctuation is always a single...
Forum: C Oct 28th, 2009
Replies: 5
Views: 536
Posted By Tom Gunn
In C++ output streams can be tied to input streams so that when a call is made to the input stream, the tied output stream flushes itself. Something like that might be happening here, but that is...
Forum: C Oct 27th, 2009
Replies: 5
Views: 309
Posted By Tom Gunn
It is always good to learn which headers contain which declarations. Including everything under the sun when you use only a small fraction of it is rarely a good idea.


Double check the way...
Forum: C++ Oct 27th, 2009
Replies: 5
Views: 270
Posted By Tom Gunn
The destructor, yes. Or better yet, use a smart pointer like auto_ptr where you do not need to worry about deleting it at all.
Forum: C++ Oct 27th, 2009
Replies: 1
Views: 209
Posted By Tom Gunn
There are three steps to inserting in an array:

Find the position of the item being inserted.
Make room for the new item by shifting all items from that position forward one spot to the right....
Forum: C++ Oct 27th, 2009
Replies: 5
Views: 270
Posted By Tom Gunn
As long as you have a copy of the pointer that was returned by new, you can delete it. You said that the pointer is stored in another object, so that object's destructor would probably handle the...
Forum: C Oct 27th, 2009
Replies: 9
Views: 255
Posted By Tom Gunn
Not quite. getchar() is declared in <stdlib.h>, which is a standard header so every compiler will have it. getch() is typically declared in <conio.h>, but only on some Windows compilers. getch() is...
Forum: C++ Oct 27th, 2009
Replies: 8
Views: 355
Posted By Tom Gunn
Give it a try before asking for help. Depending on your experience solving problems, at least an hour to several hours of solid work at it should be the minimum. Honestly, if somebody tells you how...
Forum: C++ Oct 27th, 2009
Replies: 4
Views: 208
Posted By Tom Gunn
There are left over characters in the stream that cin.get() is reading immediately. It is not blocking, so the program ends immediately and I assume the window is closing so you cannot see the...
Forum: C Oct 27th, 2009
Replies: 9
Views: 255
Posted By Tom Gunn
It is there for C99 compatibility.


In C99 getchar() will continue to return EOF if the error or end of file indicators are set on the stream. The last getchar() will not block, and that defeats...
Forum: C++ Oct 27th, 2009
Replies: 8
Views: 355
Posted By Tom Gunn
Your search always starts from position 0, that is why tokens are being duplicated. You need to skip over the extracted tokens as you go. Something like this:

#include <iostream>
#include...
Forum: C++ Oct 27th, 2009
Replies: 1
Views: 238
Posted By Tom Gunn
That class has a kind of strange way of implementing a failed search. In the constructor you pass a bogus object that will act as the sentinel value, and find() returns that object if it fails. So in...
Forum: C Oct 27th, 2009
Replies: 6
Views: 501
Posted By Tom Gunn
Do a Google search. You can download the runtime as an redistributable package from M$.
Forum: C Oct 27th, 2009
Replies: 3
Views: 192
Posted By Tom Gunn
To add to dkalita's reply, the array decaying into a pointer rule only applies to the first dimension. The pointer version of your 2D array function parameter is int (*)[MAX_COL]. You can change your...
Forum: C Oct 27th, 2009
Replies: 9
Views: 255
Posted By Tom Gunn
A previous call to scanf() of getchar() is probably leaving characters in the stream. The getchar() you are using to stop the screen only works if the stream is completely empty. You can fix that by...
Forum: C++ Oct 26th, 2009
Replies: 5
Views: 195
Posted By Tom Gunn
Your printStack() method is wrong because it prints the stack and clears it at the same time. That is problem #1. If you fix that, then your stack objects will not be cleared when they should be for...
Forum: C++ Oct 26th, 2009
Replies: 5
Views: 195
Posted By Tom Gunn
Precisely. I cannot say for sure that your isEqual() function is working as designed without a thorough test, but my eyeball test did not expose any glaring bugs. ;)
Forum: C++ Oct 26th, 2009
Replies: 3
Views: 246
Posted By Tom Gunn
Are you doing something like the following? It works OK on my end for simple currency:

#include <iostream>
#include <iomanip>

int main()
{
double values[] =
{
12.501,
Forum: C++ Oct 26th, 2009
Replies: 5
Views: 195
Posted By Tom Gunn
I get all stacks being equal because you call printStack() on both operands and printStack() pops the contents away. Both stacks are always empty. When doing these tests, make sure that you are...
Showing results 1 to 40 of 681

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC