6,741 Posted Topics
Re: main returns int, and you should validate the input somewhere or all hell could break loose. Good idea though, and a nice start. | |
Re: >is there any way one could do a square root program without sqrt or pwr functions? No, those functions are magic. There's no way you can simulate their behavior in C++ without pixie dust or phoenix feathers. One might assume that if you know how the mathematics work, you could … | |
Re: [URL="http://www.eternallyconfuzzled.com/libs/jsw_avltree.zip"]This library[/URL] is written in C, but it allows duplicates. The duplicate check is actually an [I]extra[/I] step for insertion because proper duplicate handling falls out of the usual binary search tree insertion logic. Keep in mind that the above library treats duplicates as a stack. When searching and deleting, … | |
Re: >I don't know what language your are using so I'm being vague. You could assume either C or C++ and probably hit the mark. :rolleyes: >is there any function available to enable it?? Poor man's profiler: [code] #include <stdio.h> #include <time.h> clock_t start = clock(); /* Code you want timed … | |
Re: >Can robot be coded in C++ Of course it can. >I thought AI languages like Lisp ,etc are more suitable for that? Suitable and capable aren't synonyms. | |
Re: Look through the recent threads. Not only have I explained a simple way of writing an archiver several times in the last two weeks, I've also posted sample code. | |
Re: I'm assuming you mean a buffer in the context of a stream. A stream is a sequential list of items where (in the simplest sense), the source places a single item at a time onto the stream and the destination extracts a single item in the order of insertion. In … | |
Re: That's Visual Basic, not C or C++. Please direct your question to a more appropriate forum. | |
Re: You're using integer arithmetic, any precision will be lost before the result is assigned to your float variable. Convert one of the operands to a floating-point type and it should work: [iCODE]((float)end - start) / CLOCKS_PER_SEC[/iCODE]. | |
Re: >What should i do? Post a reply to the thread that this question is concerning rather than starting a new one so that we have a clue what you're talking about. ;) | |
Re: This is an implementation-dependent operation. Without knowing your platform and compiler, we can't help you at all. | |
Re: Most of your problems can be fixed by using a stack of characters instead of strings: [code=cplusplus] #include <iostream> #include <stack> using namespace std; int main() { stack<char> s; char a; cout << "Enter: " << endl; while ( cin.get ( a ) && a != '\n' ) s.push(a); while … | |
Re: One big decision you need to make in merging is whether it's destructive or not. Are you going to remove nodes from each list and add them to the result, or copy the data into new nodes? Either way the merge works as a traversal. Select between the two lists … | |
Re: >however when I use a large number such as 100 or more it takes forever It will also probably produce incorrect results. Fibonacci numbers grow at such a large amount that unless N is small, you'll overflow a long. Even using unsigned long to protect against undefined behavior and extend … | |
Re: >gets(char[i]); FYI, booze in fact does [b]not[/b] improve your ability to write code. You'd have to be quite confused to write char[i] when you meant firstname[i], and any experienced C programmer would have to be drunk to use gets. | |
Re: [B]>is it possible to create my own simple programming language in c++?[/B] Of course it's possible. But it's harder than you probably think. | |
Re: I don't know of any, but keep in mind that the game you're looking for will either be gimped due to lack of funding or overloaded with ads and other ways of generating revenue beyond a subscription. p.s. WoW sucks, Everquest 2 is where the cool people play. ;) | |
Re: >i can sort 2 strings but can't sort 3 strings. If you can sort two strings, you know how to sort three. This is especially easy because there's a smallest, a largest, and only one inbetween. So all you need to do is find the smallest and largest before you … | |
Re: >Always use scanf() and printf(). Dangerous overgeneralization. >They are much, much faster than cin and cout. Uninformed generalization. >Also use stl algorithms, like sort, reverse and find, especialy >if they are member functions of a container class you use. This is actually good advice, though I would have worded it … | |
Re: Why do students keep expecting us to do their homework? | |
Re: If it's actually an array, there are two common ways to find the size. The first is a template that converts an array of type T to an array of type char, which can then be used as the operand to sizeof to get the number of elements: [code=cplusplus] #include … | |
Re: >system("cls"); Brilliant. So what happens if I replace the Windows cls with my own malicious cls? You've just given me control, thanks! This is what's called a back door, and you left it wide open by using an insecure technique. | |
Re: Post your code using code tags. You can find out how in the FAQ or just about any of the stickies. If you still can't figure it out, post your code anyway and a moderator will tag it for you (just this once though). | |
Re: How about a phonebook? Or an inventory system? Something that uses a simple database will be more than sufficient for a "data structure" project because you're forced to use or design a suitable data structure. | |
Re: [B]>If you expect your IDE to come fully featured then it won't be lightweight....[/B] The very definition of IDE implies a text editor, a compiler, a debugger, and build tools. vim is a text editor, not an IDE. That's why developers work with several individual tools such as vim, gdb, … | |
Re: A static function is a function with the static qualifier applied: [code] static void foo ( void ) { /* Blah blah */ } [/code] What it does is restrict visibility of the function to the translation unit in which it's declared. Functions are implicitly declared as extern by default, … | |
Re: >Though remember sprintf() does not calculate for buffer overflow. Neither does itoa. ;) >A safer version of sprintf() is snprintf() which unfortunately isn't very standard yet. It is standard, but the standard just isn't widely implemented yet. As it is, C89 is the dominant C standard, and snprintf is nothing … | |
Re: >can anyone tell me how to make it so the PC doesn't use 100% cpu? It uses 100% CPU because you're using a busy loop to pause. A true fix for the problem is "don't do that". Use some form of pause that puts the thread to sleep without affecting … | |
Re: [ICODE]system("pause")[/ICODE] represents an unsafe programming practice. Not only is the argument to the system function non-portable (your code would work on Windows but not Linux, for example), someone could replace the "pause" program on the machine with a malicious program and use it to cause trouble. Spoofing a legitimate program … | |
Re: >what does the assignment statement (*s++=*t++) return each time it gets executed It doesn't return anything. An assignment expression evaluates to the new value of the left-most operand. | |
Re: We can't tell you what's wrong with your logic if you don't post the pseudocode you have. Don't expect us to give you the solution. | |
Re: It makes more sense to work from the least significant bit (assuming your string isn't reversed), in my opinion: [code] #include <string.h> int to_int(const char *bin, int *result) { size_t len = strlen(bin); int bit_value = 1; int temp = 0; if (len > 32) return 0; while (--len < … | |
Re: >This is how I would do it You would use a recursive function for a problem clearly unsuited to a recursive solution? That's a shame. | |
Re: This is a somewhat slow solution because you end up with an expensive search, but it does what you want. The alphabet string holds all of your valid characters and the values array has the corresponding value at each index. Once you have the index for alphabet, you can get … | |
Re: >Is there a reason that I shouldn't just do this in the first place? It depends on your debugging needs. If the assertion is absolutely critical for the application to continue, [i]and[/i] the information from a failed assert is sufficient, by all means use assert. On the other hand, if … | |
Re: Two biggest problems: [list=1] [*][ICODE]count[/ICODE] and [ICODE]counts[/ICODE] are never initialized. You should initialize them both to 0. [*]In your averaging loop, you always use [ICODE]lows[MAX][/ICODE]. It should be [ICODE]lows[i][/ICODE]. [ICODE]lows[MAX][/ICODE] doesn't exist. [/list] | |
Re: >hope you are clear..bye... Please learn C before trying to teach it. | |
Re: [url=http://www.nist.gov/dads/HTML/bucketsort.html]Clickie[/url]. Bucket sort isn't as common of a term as you might think. It's actually more common to hear about variants such as radix sort. | |
Re: >The following link may be helpful I doubt it, unless the OP is still having trouble with this assignment three years later. :icon_rolleyes: | |
Re: You appear to have two Perl related questions, so I'm moving this thread to the Perl forum. | |
Re: [QUOTE]When did you start programming and what language did you start in?[/QUOTE] I started in 1996 with C. Technically my first language was COBOL, but it was too brief of a time to be meaningful. ;) | |
Re: >if you think this guy knows what he's talking about I'm sure you're simply trying to be witty, but speaking of yourself[1] in the third person is generally viewed as highly pompous. A smiley would go a long way toward helping us understand that you aren't [i]really[/i] that arrogant. >has … | |
Re: An unresolved external error is typically telling you that you've declared but not defined a function. In this case, the constructor for your Tree class. I notice that your destructor isn't implemented either, unless you're defining them in a separate file. | |
Re: [QUOTE=khotraj;1627662]Dear morons. 400mb ram and 20 gigabytes was unimaginable when C++ was made. At that time 1mb Hdd was too much and ram was less that 256Kb. check this thread out mate, and if u can modd ur phone, you can probably run Windows 95 on it as well. check … | |
Re: It's been 45 minutes. Impatient much? | |
Re: >i don't know if that's the rite procedure. The string class is designed to act like a first class type, so the operations you use on numbers should work for string objects as well. There are a few problems with your code though. >int nTemp; nTemp is the temporary storage … | |
Re: [QUOTE]Oracle Certified Java Programmer? Useless.[/QUOTE] Indeed. For that certification all I got was a silly lapel pin. Nobody asks if I'm certified and takes it on faith that I know what the hell I'm doing from previous successful projects. | |
Re: [QUOTE]Which way is the best to learn, Either to use Microsoft Visual C# or Notepad?[/QUOTE] It's beneficial to learn how to invoke your tools manually rather than rely on an IDE like Visual Studio, but not required immediately. I'd suggest starting out with an IDE for ease of use, then … |
The End.