145 Posted Topics
Re: For information on the help you can expect here with homework problems, have a look [URL=http://www.daniweb.com/forums/announcement8-2.html]here[/URL]. If you have a further look through the forums, there was a thread on your exact topic (more precisely, a discussion of how to evaluate that particular summation) a week or so back. However, … | |
Re: You are passing arr, an array of length 3 to the function, and returning arr[5]. arr[5] does not exist, as far as your program is concerned. The array does not get resized. In fact, by doing this (accessing the value of something that does not exist) your program is exhibiting … | |
Re: When you install Dev-C++, at some point you need to specify a directory where it gets installed. Whenever you (or a batch script you're executing) refers to D:\gcc, you need to change it so it refers to the directory you installed dev-C++. If you did install into d:\gcc, then presumably … | |
Re: More specifically, a [u]small[/u] piece of code that actually exhibits the behaviour you consider to be a problem. The code you've given does not appear related to the text in your post in any way. | |
Re: When you append pointers onto a vector of char, the [u]pointer[/u] is copied. You are expecting the data the pointer [u]points at[/u] to be copied. With a vector<char *> you need to explicitly copy the data as well as the pointer. An easier way would be to use a std::vector<std::string> … | |
![]() | Re: You have not initialised min, ret, cent, or invalid, which means their starting values are undefined (ie can contain random junk). Then, in your loop, you increment them. You then add the resultant values to compute total ..... Starting with junk values and incrementing yields more junk. Adding junk values … |
Re: Heaps of things wrong with your code. 1) You need to decide if you are working with a 1D or 2D data structure. 2) You need to decide whether your copy constructor does a deep copy (i.e. dynamically allocating rows and columns, and then copying all the values). At the … | |
Re: You're paraphrasing, based on where you [u]think[/u] the problem is, and the end result is that you haven't provided enough information for people to help. You haven't explained what you mean by "non-working". Does the code fail to compile? Or does it compile, but fail to link? Or does it … | |
Re: [QUOTE=cam875;701925]i dont understand the memset thing char* binary = new char[ElementAmount]; memset(binary, 0, sizeof(binary));[/QUOTE] That code is a beginner's error, and tends to yield bugs that are hard to track down. The memset() call should, presumably, be "memset(binary, 0, ElementAmount);" to set all bytes in the dynamically allocated array binary … | |
Re: [QUOTE=Denniz;701773] Normally I would do something like this for dynamic allocation: [Code] Contestant* C = NULL; C = new Contestant; if(C) // test valid allocation { // do whatever you want here // Memory deallocation delete C; C = NULL; } [/Code][/QUOTE] Your approach will not work: operator new does … | |
Re: [QUOTE=Ancient Dragon;700326]I have no idea how your teacher's program works -- you would have to post it. I can only suspect he used one of the huge integer libraries like I previously suggested. Its also possible he used strings instead of integers to avoid the limitations of integers.[/QUOTE] Oh, please! … | |
Re: RTFM is the rule, google is your friend that makes it easy to follow the rule. Results of searching for LNK2019 yielded [URL=http://msdn.microsoft.com/en-us/library/799kze2z(VS.80).aspx]this[/URL] and of searching for LNK1129 yielded [URL=http://msdn.microsoft.com/en-us/library/z98k84c3(vs.71).aspx]this[/URL] as the [i]first hits[/i]. In short, you have code that is trying to call a function (or multiple functions) you … | |
Re: Practically, when working with templates, it is necessary to have the template definitions (ie the implementation of template member functions) in the header file. It is not possible (with most compilers) to compile templates separately. The reason is that, when using templates, the compiler needs to see the definition (ie … | |
Re: [QUOTE=ambarisha.kn;699975]But if i make DB, DC as char its not possible to add 1024. then how to add 1024 bytes to that[/QUOTE] You need to make DB, etc [u]pointers to[/u] char. sizeof(char) is 1, by definition in the standard. So if DB is your base address, DB + 1024 is … | |
Re: Try describing to us what [u]you[/u] think the code does, and we'll check if you're right (or how right you are). You'll learn more if you think it through and describe what's happening so others can understand rather than simply getting others to do the work for you. ![]() | |
Re: The cause of your problem is almost certainly code executed [u]before[/u] your red lines are reached. My guess - although you haven't shown them - is that the problems really occur in your input() function or, possibly in your createArray() or removeDup() functions. I'd even guess further that - in … | |
Re: [QUOTE=ArkM;697975]Because of no total linear memory space concept in platform-independent C++ language.[/QUOTE] That's not true. The memory model in C and C++ is linear. Or, at least, the memory available to a program consists of a series of one or more sequences of contiguous bytes. However, a pointer is not … | |
Re: Your basic problem is that you need to ensure two bits of information come together: the object to be acted on (eg a pointer to that object) and the function to act on it (eg the member function). glutMouseFunc(MouseButton) only passes information about the function to be called. That function … | |
Re: While tempted to suggest "draw and quarter", the fairest treatment would be forcing them to pay my internet bill. After all, if they consume my bandwidth and quota without my permission, they should pay me for the usage. The fact I pay for an internet connection does not bestow permission … | |
Re: Well, yeah, you can look at the first character, but that will not distinguish "Adam" from "Anthony". If the first characters are equal, then it's necessary to look at the second .... and then third, and so on - which is exactly what strcmp() does. As a rough rule, in … | |
Re: [QUOTE=Sci@phy;694893]Thx, I'm going to do that. But just out of curiosity, let's say i write: [CODE] string *ptr = new string; string *alt = ptr; ptr->assign("Happy Day"); cout<<"On alt adress is: "<<*alt<<endl; cout<<"deleting ptr"<<endl; delete ptr; cout<<"ptr adress: "<<ptr<<endl; cout<<"alt points to: "<<*alt<<endl; [/CODE] Now program is terminated as it … | |
Re: The standards specify that elements of declared arrays are contiguous. N-dimensional arrays are actually arrays of (N-1)-dimensional arrays. So ..... the compiler is required to do what you want (at least, in terms of storage). In terms of mechanism of element access (eg accessing element_in_N_dimensions vs equivalent access of element_in_one_dimension) … | |
Re: Stepping through a MS-DOS based program in an IDE trying to find the source of a bug. Next thing: the computer did a warm boot, but was unable to come up again because it couldn't find a system drive. After restoring from backup (and being very thankful I had a … | |
Re: [QUOTE=coveredinflies;690909] Both ways compile so as long as this isn't just lucky I will just learn without the & sign as it makes more sense to me (though maybe it shouldn't lol). [/quote] Without the ampersand (&) the function creates and returns a temporary copy of the object it is … | |
Re: 1) First, represent a polynomial (of the form c_0 + c_1*x + c_2*x^2 + .... c_n*x^n) is represented by an array with elements (c_0, c_1, c_2, c_3, .... c_n). 2) Work out how to multiply two arbitrary polynomials together. ie. given a polynomial A (a_0, a_1, a_2, a_3, .... a_n) … | |
Re: Talking about using a sledgehammer to crack a nut. No need to use high precision integers at all. (a^b) mod c can be evaluated using a loop, using modulo arithmetic. The basic property you need to know is that (x*y) mod z is equal to ((x mod z)*(y mod z)) … ![]() | |
Re: According the the C++ standard (Section 5.8 para 1 "Shift operators") "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand." In other words, assuming your unsigned type is 32 bits, you are not allowed … | |
Re: Not even close. You have declared myclass's length() method as taking one argument, and yourlen() calls it with two arguments. Similarly, yourlen() is declared with no arguments, but when you call it you pass two to it. (I'll ignore the typo of calling a.youlen() rather than a.yourlen()). If you declare … | |
Re: [QUOTE=Jawahar prabhu;689845]hi i'm new for c++, i tried to work with mouse pointer on my run window but i dont know how to make interrupt to do it. thanks[/QUOTE] Standard C++ does not allow you to work with the mouse (or interrupts). The techniques are operating system and compiler/library dependent … | |
Re: Firstly, your variables a, b, and c are uninitialised: their value before entering the loop could be anything. As to your loop, it doesn't really make sense. You only need two variables. An index, that gets a value of 1 first time through the loop, 2 the second time, 3 … | |
Re: [QUOTE=jencas;688246]- avoids dangerous recursive call of main() [/QUOTE] In C++, recursive call of main is not allowed at all. To answer the original question, if you must be able to execute a program that reads from standard input and writes to standard output, you need to investigate input and output … | |
Re: It's say the chance of messing up due to inheritance is the least of your problems. Attempting to avoid problems due to X without even a basic understanding of how X works is a recipe for disaster. And trying to design a framework on that basis is asking for trouble. … | |
Re: Look up the specification of localtime(). My recollection is that systime->tm_year would be the number of years since 1900. 2008-1900, last I checked, yielded a value of 108. | |
Re: Three possibilities I can think of offhand. 1) The way you have created the individual objects (which you haven't shown) is inconsistent with the way you're destroying them. 2) Some operation of the Text type is invalid (eg it mangles a pointer to data internally). 3) Some other code is … | |
Re: Dragon's approach will work .... the only other obstacle is the fact that most systems allow a process to have only a small number of files open simultaneously. If you exceed that number, ..... | |
Re: The double quotes have to be around the full path names, not around the filename. The command string you need to build is probably "del [color="red"]\"[/color]C:\users\robocop\desktop\a b c.txt[color="red"]\"[/color]" | |
Re: [QUOTE=Ancient Dragon;681922][CODE] void functijon(int **array) { array[0][1] = 123; } [/code] The above is a 2 dimensional array of integers. [/quote] Not really. array is a (misnamed) pointer to a pointer. It is not a 2D array. However, in some circumstances (eg the code example you gave, although I won't … | |
Re: A class declaration is anything, essentially, that tells the compiler a name is for a class. For example; [code] class ClassName; [/code] is known as a "forward declaration". A class definition is a type of declaration that provides enough information that a compiler can create instances of the class, compute … | |
Re: That's the way it is. The compiler adds a padding byte. The reason is that each element of an array is required to have a distinct address, and the size of an array with n elements is computed as n*sizeof(element). This would not work if sizeof(element) could yield a zero … | |
Re: [QUOTE=sadaka;392919] My "Makefile" contains this: [code]EngineMain : EngineMain.o Engine.o (tab)gcc -o EngineMain.o Engine.o EngineMain.o : EngineMain.cpp Engine.h (tab)gcc -c -g EngineMain.cpp Engine.o : Engine.cpp Engine.h (tab)gcc -c -g Engine.cpp [/code] [/QUOTE] The rule above for EngineMain will not function as intended. It should probably be; [code] EngineMain : EngineMain.o Engine.o … | |
Re: On the other hand, Arkm, don't advocate valarray without a particular reason. The original post provided no particular reason to prefer valarray over a vector. The only requirement stated is ability to represent an array of float with length unknown at compile time. Both valarray and vector meet that requirement, … | |
Re: That code is too big for anyone to bother looking at. Try eliminating code to produce a [u]small but complete[/u] code sample that exhibits your problem. If you get lucky, you will find/fix the problem in the process of producing that small code sample. If not, people will be more … | |
Re: There are a few factors that conspire to make you have less disk available than the labeled disk size. Firstly, marketeers of hard disks conspire to make you think you're getting more than you are, by defining a GB as a million bytes rather than as 1024*1024*1024 (which is how … | |
Re: The reason is that Base is a [u]private[/u] base class of Derived. Implicit conversion from "pointer to Derived" to a "pointer to Base" relies on public inheritance. Code using Derived (i.e. your _tmain() function does not have access to private members or bases - that is what "private" means. Your … | |
Re: [QUOTE=MONODA;675898]i read that a while back and didnt like it; it seems like all the guy is doing is describing himself and saying everyone else isnt a real programmer.[/QUOTE] And you're suggesting that's unusual???? Virtually every programmer I've ever known considers he or she is the only real programmer. |
The End.