436 Posted Topics

Member Avatar for Ineedhelpplz

Your code has three immediate problems: [LIST=1] [*]The i variable is not initialized to 0. [*]getchar() is only called once, not every time the loop iterates. [*]The array is not terminated with a '\0' character. [/LIST] If you fix those things, it should work.

Member Avatar for Ineedhelpplz
0
152
Member Avatar for jdam7459

C++ treats the closing >> as the right shift operator, not two closing brackets for a template instantiation. You need to separate those two characters with white space: [code] Stack<Tree<int> > stack; [/code] C++0x is the next revision of the standard, and it should fix that problem.

Member Avatar for Tom Gunn
0
82
Member Avatar for lotrsimp12345

Containers are implemented using data structures, and the implementation of a container is not usually specified, so containers are a more abstract concept than data structures.

Member Avatar for Tom Gunn
0
82
Member Avatar for konohastar

[QUOTE]1) Using the getchar() function, you need to flush the input buffer to get rid of the newline character[/QUOTE] As a corollary, [ICODE]fflush(stdin)[/ICODE] is not the way to flush the input buffer because fflush() is only defined to work on output buffers. A portable way to flush is getchar() in …

Member Avatar for konohastar
0
241
Member Avatar for Simzz
Member Avatar for nateuni

[QUOTE]When I stepped through on the debugger it did not come up, can anyone shed some light on what I am doing wrong?[/QUOTE] Memory corruption can happen and not show symptoms until much later. The code you posted is not broken in any way, so the problem is probably earlier …

Member Avatar for Tom Gunn
0
674
Member Avatar for Gaiety

Your isbal() function only tests the root, it should recursively test every node because there are trees that can be unbalanced but still have a height difference of less than 2 from the root. The definition of height balanced is that when every node is tested as an individual tree, …

Member Avatar for dkalita
0
112
Member Avatar for MStan537

Try combining the tests like this: [code] int code; while ((code = scanf("%f", &fDollars)) != 1 || fDollars <= 0) { printf("invalid amount. please enter a positive amount: "); fflush(stdout); if (code != 1) FLUSH_STDIN(); } [/code] Further reading for extra credit can be found [URL="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm"]here[/URL].

Member Avatar for MStan537
0
171
Member Avatar for jakesee

[QUOTE]the only way i know of is using the initialisation list[/QUOTE] That is the ideal way, and it is required if the Secret class does not have a default constructor. If the Secret class does have a default constructor you can use assignment in the constructor body: [code] class Secret …

Member Avatar for Tom Gunn
0
148
Member Avatar for Mark198995

Then terminate it there. :) If you do not do something to break the line of execution, you will step over each statement in order. Try this to kill the program from the else clause: [code] else { system("pause"); return 0; } [/code] This matches your end of main code, …

Member Avatar for Tom Gunn
-1
110
Member Avatar for jakesee

[QUOTE]having const after a member function means that, that function will not and shall not change any of its variables. [/QUOTE] This is misleading. The method can change any of its local variables and non-const parameters, but it cannot change the state of the object. That means non-mutable data members …

Member Avatar for jakesee
-1
95
Member Avatar for nateuni

[QUOTE]I have been reading about memset but my understanding is it will not work for a struct.[/QUOTE] There is nothing about a struct that causes memset() to fail, the problem is with the member types. [ICODE]memset(pobj, 0, n)[/ICODE] will set n bytes starting at pobj to all bits 0. All …

Member Avatar for nateuni
0
130
Member Avatar for serkan sendur

The only built in compiler I remember was for BASIC, a long time ago. I do not think even that is built into the latest Windows systems. If you want to stretch the definition of 'compiler', you can write and run HTML on a fresh Windows install. :D The reason …

Member Avatar for yellowSnow
0
2K
Member Avatar for johndoe123

[QUOTE][CODE]char AorB(char A, char B) { char T = rand%2 ? A : B ; return T; }[/CODE][/QUOTE] [ICODE]rand()%2[/ICODE] might not be very random. Historically rand() has been written with very non-random low order bits, and using modulus to fit the range uses the low order bits. [ICODE]rand()%2[/ICODE] only uses …

Member Avatar for Nick Evan
0
10K
Member Avatar for kyumi419

Not that I can remember. But they are easy to write, so it is not a big loss. :)

Member Avatar for Tom Gunn
0
56
Member Avatar for oling

[QUOTE](which will ensure a cast to an unsigned long, the biggest unsigned integral type)[/QUOTE] Unless size_t is unsigned long or integral promotion makes it an unsigned long, the only thing you ensure is undefined behavior because the type of the value and the type of the format string do not …

Member Avatar for oling
0
2K
Member Avatar for Frederick2

[QUOTE]I simply didn't know that and it amazed me.[/QUOTE] Why did it amaze you? There are two good options for how to manage function calls in the condition: [LIST=1] [*]Call the function every time the condition is tested. [*]Call the function once and capture the result, then use the captured …

Member Avatar for Frederick2
0
126
Member Avatar for Darth Vader
Member Avatar for serkan sendur

[URL="http://www.amazon.com/Programming-Environment-Addison-Wesley-Professional-Computing/dp/0321525949/ref=sr_1_7?ie=UTF8&s=books&qid=1253643528&sr=1-7"]Advanced Programming in the UNIX Environment[/URL]. Anything by W. Richard Stevens is good.

Member Avatar for Tom Gunn
0
96
Member Avatar for Darth Vader

A 2D managed list of strings with an initial capacity of 1000 would be declared like this: [code] List<List<String^>^>^ vector1 = gcnew List<List<String^>^>(1000); [/code] You can use typedef to make that simpler too. ;)

Member Avatar for Darth Vader
0
1K
Member Avatar for mz_rigel

The frequency of a number is how many times it appears in the list. A histogram is a visual representation of the frequency. Start by ignoring the histogram and only display the frequencies as a list of counts. I can think of two easy ways to count the frequency. A …

Member Avatar for Tom Gunn
0
200
Member Avatar for karthik.u

You can pass a comparator to the set as a constructor argument, but it is just as easy to overload operator< for the struct: [code] #include <cstring> typedef struct CONFIG_ { char app[10]; char key[10]; friend bool operator<(CONFIG_ const& a, CONFIG_ const& b) { return std::strcmp(a.key, b.key) < 0; } …

Member Avatar for Tom Gunn
0
2K
Member Avatar for Whilliam

[QUOTE]I can get it to save and load but when I try displaying it, its gonna have a General Protection Exception error.[/QUOTE] Your data structure is probably getting corrupted during the load. Maybe you are not terminating one of the lists with NULL, or not handling NULL cells as a …

Member Avatar for Tom Gunn
0
151
Member Avatar for Gaiety

When you say 'strict binary tree', you mean that each node has only two links? You can do it, but if your node struct only has left and right pointers, it is kind of pointless to do a test that is guaranteed at design time. ;) If you mean to …

Member Avatar for Tom Gunn
0
1K
Member Avatar for kyumi419

Start by making a subset of the pattern: [code] *0000000* 0*00000*0 00*000*00 000*0*000 [/code] This is easier to visualize with two counters to mark the stars. After you get this one, you can add the central star that does not ever move.

Member Avatar for kyumi419
0
205
Member Avatar for nateuni

[QUOTE]Is this possible that instead of typing - program.week[0].workout[0].exercise[0].exerciseName everytime I want to access an element. That I can access the elements of the most nested struct via a pointer. [/QUOTE] Yes. If you have an object, you can have a pointer to it: [code] #include <stdio.h> struct A { …

Member Avatar for nateuni
0
527
Member Avatar for Gaiety

I cannot say what the problem is without more code to test with, but it might be that your runtime is not flushing stdout. Try printing a '\n' character or calling [ICODE]fflush(stdout)[/ICODE] after the fwrite() to force a flush.

Member Avatar for codeguru_2009
0
1K
Member Avatar for jhunluis

C does not support nested functions. You need to move the function definitions outside of main().

Member Avatar for Salem
0
166
Member Avatar for suutukil

[QUOTE=firstPerson;987910]What you could do is, since you are getting inputs, you can make sure that the inputs are greater than the last input. example run : [code] Please enter a number : 3 Please enter a number greater than 3 : 5 Please enter a number greater than 5 : …

Member Avatar for suutukil
0
623
Member Avatar for OneDreamCloser

Assuming the input buffer you are testing is the same input buffer that was allocated, the only thing that stands out in the code you posted is this: [code] inputBuffer->inputPriorityList = createList(inputBufferName) ; [/code] createList() might be returning a null pointer in some cases.

Member Avatar for Salem
0
135
Member Avatar for Grn Xtrm

Good start! C is different in a few ways though. Declarations need to be the first thing in a block unless you are compiling under C99, so your C code will not compile with most compilers. [QUOTE][CODE]printf("N %2.2f, factorial %2.2f \n" ,i,factorial(i));[/CODE][/QUOTE] You need to be very careful with printf() …

Member Avatar for Grn Xtrm
1
202
Member Avatar for Gaiety

[QUOTE]if i have only one node in the list one function displays height as -1 and other displays 0[/QUOTE] Both are right. The function that returns -1 is probably treating an empty tree as an error case and returning a suitable code. The function that returns 0 is treating an …

Member Avatar for Tom Gunn
0
120
Member Avatar for cristian.sorin

[QUOTE]the program continue showing lines from file even the file don't exist anymore. My problem is that i don't understand why it still prints lines after file deletion.[/QUOTE] I do not know how CentOS manages files in use, but it looks like the file is loaded into either memory or …

Member Avatar for codeguru_2009
0
180
Member Avatar for krellor

[QUOTE]I am adding an integer to a type largeInt, but I have not created an overloaded method that accepts largeInt and numerics as input, only one that inputs largeInts and strings. It compiles and runs fine without even a warning.[/QUOTE] The largeInt class has an implicit constructor that takes a …

Member Avatar for krellor
0
146
Member Avatar for dpreznik

CArray<> is an MFC class, right? The problem is almost surely going to be in your code, not the code of CArray<>. Can you post a small program that has the same error so that everyone can see how you are using the class?

Member Avatar for Tom Gunn
0
213
Member Avatar for Gaiety

An expression tree is a tree, not necessarily a binary tree, that holds the parts of an expression the same way a stack might hold them for prefix evaluation: [code] Expression: 2+(4*3) Stack: [+][2][*][4][3] Expression Tree: + / \ 2 * / \ 4 3 [/code] Look up how to …

Member Avatar for Tom Gunn
0
84
Member Avatar for onaclov2000

Grab the whole line, then parse it. You can parse with string streams using the same syntax as cin: [code] string line; getline(cin, line); istringstream iss(line); int value; while (iss >> value) cout << value << '\n'; [/code]

Member Avatar for necrolin
0
122
Member Avatar for volscolts16
Member Avatar for Salem
0
184
Member Avatar for Gaiety

[QUOTE]Do we need to make any changes in the structure of tree , i mean any extra pointers in the structure declaration to hold the parent address when going down the tree.[/QUOTE] Having parent pointers can help make the code simpler, and you do not need to worry about managing …

Member Avatar for Tom Gunn
0
171
Member Avatar for D.JOHN

[QUOTE]but what if I want the hexadecimal 199 to be displayed in binary?[/QUOTE] printf() does not have a conversion to binary. The C++ library has a bitset<> class that will indirectly do it for you, but you need to use cout to print directly, or manually convert to a string …

Member Avatar for D.JOHN
0
209
Member Avatar for MattyRobot

I think it is better to learn more about C++ than the basics first. You can learn about writing game logic without adding the complexity of graphics to your program. If you start learning how to make graphics with incomplete knowledge of C++, you will end up struggling with the …

Member Avatar for MattyRobot
0
121
Member Avatar for pymatio

[QUOTE][CODE]if (i != n){ cout << i << '\n' << n << '\n'; files += line; files += '\n'; } [/CODE][/QUOTE] What is [ICODE]files[/ICODE]? You use that identifier as if it were a string, but it is never declared or defined anywhere.

Member Avatar for Ancient Dragon
0
236
Member Avatar for atch

Compilers usually have macros for versioning. You can use those to figure out which compiler is doing the compiling: [code] #if !defined(_MSC_VER) #error Microsoft Visual Studio is required #endif [/code]

Member Avatar for Tom Gunn
0
67
Member Avatar for Phloxicon

[QUOTE]I understand both of those facts but I thought that here, I'm only accessing the private members via the friend class, which I thought would be okay.[/QUOTE] Making a friend to a class does not make the private members public. FriendClass can access UnrelatedClass' private members, but those private members …

Member Avatar for Tom Gunn
0
285
Member Avatar for MattyRobot

You can call a function provided it has already been declared: [code] void afunction(); class example { public: example(); ~example(); void doSomthing() { afunction(); } }; void afunction() { //do more things } [/code] A definition is also a declaration, so you can move the definition above your class definition …

Member Avatar for rughead
0
158
Member Avatar for lancevo3

[QUOTE][ICODE]return *nodePtr->data;[/ICODE][/QUOTE] Unless data is a pointer to a pointer, this either returns data or throws an indirection error. To get the address of an object you use the & operator: [code] return &nodePtr->data; [/code]

Member Avatar for Tom Gunn
0
98
Member Avatar for anupa

You don't need to store them all at one. Instead, loop it: [code=c++] while (getline(ifs, line)) { // do your thing } [/code] When there aren't any more lines, getline will return a condition that stops the loop.

Member Avatar for anupa
0
1K
Member Avatar for JETFUSION

[QUOTE][CODE]for (int j = 1; j <= (2 * i - 1); i++)[/CODE][/QUOTE] Your bug is the reason why I do not use i and j for counters. ;) They look so much alike it is easy to mistype and not be able to see it. In the code above …

Member Avatar for tux4life
0
127
Member Avatar for rmeltg

Dave Sinkula's idea is good, but I think it is easier to see what goes on by printing the intermediate results too, but in binary instead of hex: [code] #include <iostream> #include <limits> #include <bitset> int main() { using namespace std; //int tmp = 0xff000000 | ((int)(val) << 16 | …

Member Avatar for rmeltg
0
110
Member Avatar for Tom Gunn

This is an example of how to turn numbers into words. 1473 would get translated to "one thousand four hundred seventy three", for example. The class has a simple interface and can handle any value representable by unsigned int. The implementation recursively processes groups of 3 digits using table lookups …

Member Avatar for William Hemsworth
3
512

The End.