436 Posted Topics
Re: There are three steps to inserting in an array: [LIST=1] [*]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. [*]Copy the new item into the position that was vacated. [/LIST] Graphically it … | |
Re: [QUOTE]when i press Ctrl+F9 , the output screen comes and goes without stopping for a while. Please note that i have included "#include<stdio.h>" and i am using "getchar()" function do stop the screen. [/QUOTE] A previous call to scanf() of getchar() is probably leaving characters in the stream. The getchar() … | |
Re: 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 your case you will compare [ICODE]mytree->find(joe)[/ICODE] against [ICODE]bob[/ICODE], since you passed [ICODE]bob[/ICODE] … | |
Re: Yes, null bytes with a value of 0x00 are used as padding for alignment purposes. | |
Re: Are you doing something like the following? It works OK on my end for simple currency: [code] #include <iostream> #include <iomanip> int main() { double values[] = { 12.501, 1254.0, 124.15, 10321, 1.1256 }; const int sz = sizeof values / sizeof *values; std::cout.imbue(std::locale("")); for (int x = 0; x … | |
Re: 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 clearing out the stack at the right time. | |
Re: The getline() method works with char pointers, and the non-method getline() works with string objects. | |
Re: It works OK for me. Maybe the problem is how you are printing the double that atof() returns. What does the following program print when you run it? [code] #include <iostream> #include <iomanip> #include <string> #include <cstdlib> int main() { std::string s("500.00"); std::cout << std::fixed << std::setprecision(2) << std::atof(s.c_str()) << … | |
Re: [QUOTE]how we can check a linkedlist of char have a palindrom or not [/QUOTE] The same way you do it with an array. Walk two iterators from each end toward the middle until they meet. If the iterators match the whole way, the sequence is a palindrome. Of course, if … | |
Re: [QUOTE]hw can i make x and y give me the lowest form of the rational numbers [/QUOTE] Do you mean you want to [URL="http://cboard.cprogramming.com/c-programming/24494-reducing-fractions-entering-fraction-form.html"]reduce a fraction[/URL]? [QUOTE][CODE] HERE: scanf("%d", &v); if(v==0) { printf("Don't use 0 \n"); goto HERE; } [/CODE][/QUOTE] [ICODe]HERE[/ICODE] is a terrible name for a goto label. But … | |
Re: [QUOTE]1. Whether I can use ASCII code for to print special symbols, like I have done above in 3 cases.[/QUOTE] What are special characters? Are they the glyph characters that are neither digits nor latin alphabet characters? Are they control characters? What about extended characters? All of the above? You … | |
Re: [QUOTE]so no one has solved it still............[/QUOTE] If anyone has bothered, they will not post the code. It is counterproductive and against Daniweb's rules to help people cheat on their homework. | |
Re: [QUOTE]Are you using the <string> header?[/QUOTE] [icode]System::String[/icode] is not the same as [icode]std::string[/icode]. The former is the .NET framework's string class that is used in C++/CLI code. [QUOTE]I have trolled the interwebz looking for an answer and can't find anything helpful.[/QUOTE] Your question is a Microsoft [URL="http://support.microsoft.com/kb/311259"]knowledge base article[/URL]. It … | |
Re: What do you mean by "it's not working"? Are you getting a compile time error? A run time error? "It's not working" is not a helpful description of the problem. | |
Re: [QUOTE]Can anyone help me with the algorithm for the height of a n-ary tree, I have been looking and could only found for a binary tree[/QUOTE] The basic algorithm is the same. The only difference is that instead of just following the left and right links, you follow n links. … | |
Re: [QUOTE]const just says the function will not change anything [/QUOTE] Kind of. const can only be applied to methods, and it means two things: [LIST=1] [*]The immutable state of the object will not be changed within a const method. [*]The const method can be called by objects that are declared … | |
Re: Traditionally it is done with a header file and an implementation file: [code] // myarray.h #if !defined(MYARRAY_H) #define MYARRAY_H #define MYARRAY_SZ 100 extern int myarray[]; #endif [/code] [code] // myarray.cpp #include "myarray.h" int myarray[MYARRAY_SZ]; [/code] [code] // main.c #include <iostream> #include "myarray.h" int main() { for (int x = 0; … | |
Re: Both and neither. Your question is much too vague to answer. Any objective comparison needs to be very specific about what is being tested and using equivalent code. | |
Re: Usually libraries will come with a .lib or .dll file that you can link with, and headers for compiling. But if you have all of the source, you might be able to build it all fresh too. | |
Re: Look up the next_permutation() and prev_permutation() functions in the <algorithm> header. Literally, by the way. They are template functions, so you can open that header as a text document and read the implementation to figure out how it is done. :) | |
Is it possible to add the last post part from the forum list to the favorites list? And maybe also a link to mark all favorite forums as read? :) | |
Re: [QUOTE]confused here on how the mapping is done between read ,write and scanf ,printf. because read/write takes file descriptors, buffers and size of data where as printf and scanf takes the variable lenght args: format strings and arguments[/QUOTE] It is not a direct mapping. printf() for example does a lot … | |
Re: The easiest way to do this is to open the .cpp file and display it using cout. As a hint for a program displaying its own code, there is a preprocessor macro called __FILE__ that evaluates to a string with the name of the current file. This is the simplest … | |
Re: [QUOTE]i am very poor in programming coding ... [/QUOTE] The only way to fix that is by writing code. It is best to start small and build on your achievements than to start with something too complex for your skills. | |
Re: Close, but a temporary copy of the object is still an independent copy. C++ does not make reference copies of objects like Java or C#. To replace the object the iterator refers to, you need to assign to the dereferenced iterator. This will overwrite the object that it refers to: … | |
Re: When the value of a variable changes without any kind of modifying statement on it, you should look for memory corruption like buffer overflows and bogus pointers. I can help you look for it if you can pare your code down to a small but complete program that still has … | |
Re: [QUOTE]is sizeof an opearator(i actually studied it as a operator but then not so serious about the things)[/QUOTE] Yes, it is an operator just like [ICODE]return[/ICODE], or [ICODE]=[/ICODE], or [ICODE]<<[/ICODE]. Sometimes it looks like a function because of parentheses around the operand, but that is just an appearance thing. Any … | |
Re: A red black tree is more than just a binary search tree with nodes marked red and black. The structure also has to be balanced according to the red black rules. Why not do a red black insert in the first place instead of trying to convert between a simple … | |
Re: Pointers to functions and pointers to methods are not the same thing. A pointer to a method is really an offset into the class, not a real pointer with an address value. You need to make two overloads of the Integral() function. One that takes a function pointer and one … | |
Re: To position the triangle is as easy as printing out as many spaces as the position for each line: [code] for (int x = 0; x < position; ++x) cout.put(' '); [/code] Clipping the triangle is only a bit harder. Calculate the current position and if it exceeds the width, … | |
Re: SAX was designed for hashing strings and is supposed to be really good for it: [code] unsigned hash(string const& key, unsigned tableSize) { unsigned hashVal = 0; for (int x = 0; x < key.length(); ++x) { hashVal ^= (hashVal << 5) + (hashVal >> 2) + key[x]; } return … | |
Re: [QUOTE]1) Can't: #include "stdafx.h" - fatal error:file or directory not found.[/QUOTE] I would recommend that you forget stdafx.h exists. It is easier in my opinion to start with an empty project and use the standard headers than to work with VC++'s precompiled headers. The other project types all start out … | |
Re: [code] lookin dat dar string izzit dat vowuel? yup, stop lookin' nope, keepa goin' didja find it? yup, hola! nope, hola louda! [/code] | |
Re: [QUOTE]Numbers which start with a 0.[/QUOTE] You should ask whether leading 0's should be taken into account, because if you write code that does so and it is not part of the problem, you will not get the question right. Leading 0's are usually only used as padding for display … | |
Re: [QUOTE][CODE]d=strupr(s1);[/CODE][/QUOTE] d is an array, but strupr() returns a pointer to char. That is a type mismatch on the one hand, and on the other you cannot assign to an array. | |
Re: Any shared resources should be protected somehow. If the singleton is a singleton across threads and not a singleton per thread then you do need to think about concurrency errors. | |
Re: [QUOTE]Is there any way to make VS2005 use the Aztec C compiler commands (from Aztec BIN folder)?[/QUOTE] No, but if the code does not rely on extensions to the language/library by Aztec C, you can probably port the code to VS2005 without much trouble. I am not sure if the … | |
Re: [QUOTE]i would like to know the way we can make user enter a number in a menu reply perhaps so that he doesnt have to press the enter key[/QUOTE] For this question we need to know what compiler and OS you use because there are no portable answers that will … | |
Re: That sounds like a good beginner's exercise. You should totally write a program like that. :) | |
Re: Functions cannot be nested in C++. They have to be at global, namespace, or class scope. You should be able to fix the error by moving the definition of CreateAllNodes() so that it comes before the definition of main(). | |
Re: [QUOTE]I cant use Visual Studio 2008 (which Id like to) as it uses it own compiler.[/QUOTE] Most IDEs, including Visual Studio, can be configured to use a different compiler. I am wondering why you think gcc is the best C compiler. It is certainly good, but not really much better … | |
Re: [QUOTE]If you compile with -Wall you should've seen the warning warning C4700: uninitialized local variable 'a' used and that's because class A doesn't have a constructor.[/QUOTE] -Wall is not a switch in VC++, but that warning is thrown on the default warning level, and the "internal exception" I get when … | |
Re: [QUOTE]How to pass array of pointers to structures using functions in C?[/QUOTE] Pointers are very regular. Once you know the basics, you can apply those basics to any level of indirection and everything will work the same way. Start with the two basic rules: [LIST=1] [*]A pointer variable is declared … | |
Re: [QUOTE]Is it true that some compilers require void before main ?[/QUOTE] No. Any compiler that claims to compile C is required to allow a return value of int from main(). A return of void from main() is an extension that only some compilers allow. These two definitions of main(), and … | |
Re: [QUOTE]maybe its a compiler issue.[/QUOTE] It is a normal result of stream I/O in C. The problem is that there is still a character left in the stream after calling scanf(), and getchar() eats it without blocking. The IDE you are using probably closes the window after main() returns, so … | |
Re: One thing that causes thrashing is when physical memory is filled up and spills over into virtual memory. Virtual memory is disk based instead of RAM based, so it is much slower to access data stored in virtual memory. Anything that uses RAM can potentially cause that form of thrashing. … | |
Re: [QUOTE]I also need help with push. I couldn't figure out how to complete the definition or routine for it.[/QUOTE] It looks like you are using a two way linked list for the implementation. If that is the case, push is no harder than the other operations. Push() is the inverse … | |
Re: Strings in C are terminated by a '\0' character, but there is no magic that stops loops on it. Nothing stops you from walking past that character if the loop does not account for it. Change your loop to something like this and it will stop in the right place: … | |
Re: [QUOTE]how hard is the step from making console application to real world apps?[/QUOTE] Many real world apps are also console apps, so the only real difference is that those GUI apps use a GUI library to make a pretty looking interface on top of the same kind of stuff that … | |
Re: [QUOTE][CODE]main()[/CODE][/QUOTE] If you do not specify a return type for main(), it does not mean you are exempt from returning a value. This feature is called implicit int. It means that if a data type is expected but not provided, int is assumed. So these two definitions of main() are … |
The End.