825 Posted Topics

Member Avatar for sketchiii

[QUOTE=sketchiii;1477792]... but is there a way to do it using C only?[/QUOTE] C programs execute in memory. Once that process' memory is unloaded (i.e. the program exits) the values stored there are no longer valid. You can do several things to create persistent memory - which you choose depends on …

Member Avatar for sketchiii
0
194
Member Avatar for relient28

It is not [i]necessary[/i] to initialize variables. The problem you run into with memory that is not initialized is that if you try to [b]read[/b] it you could end up with strange behavior. As gerard4143 mentioned, this is doubly important with pointers as anything other than a NULL value could …

Member Avatar for L7Sqr
0
131
Member Avatar for Mr.UNOwen

Using select is a viable approach on some systems. There are other input query mechanisms on other platforms. What system are you operating in?

Member Avatar for Mr.UNOwen
0
101
Member Avatar for niranjan889

Use [icode]#include <string>[/icode] and [icode]#include<iostream>[/icode] instead of the versions you have.

Member Avatar for VernonDozier
0
93
Member Avatar for xcarbonx

If the only thing you are worried about is that the number of parenthesis are balanced then you dont need a stack - although if you decide to transform the equation (to RPN, for instance) or evaluate it you will. To ensure balance the following algorithm will work:[code]// pseudocode while …

Member Avatar for L7Sqr
0
94
Member Avatar for jkoske

GDB is a very powerful tool. It has many interfaces (DDD, kdbg, ...) The usefulness of this tool - regardless of its interface - is going to be your level of involvement. The more you use it and explore it's facilities the more comfortable you will become with the tool. …

Member Avatar for Stefano Mtangoo
0
109
Member Avatar for lochnessmonster

Templates are designed to generate code at compile time. Due to this design, the only way they will ever contribute to the ultimate size of a binary is by making it larger. Think of templates as incomplete sections of code that get filled in at compile time. So if you …

Member Avatar for L7Sqr
0
996
Member Avatar for xxxferraxxx

[code]#include <stdio.h> #include <stdlib.h> #include <time.h> int cmp (const void * a, const void *b) { return rand() & 0x1; } int main () { char alpha[] = "abcdefghijklmnopqrstuvwxyz"; srand(time(0)); qsort (alpha, 26, 1, cmp); return printf ("%s\n", alpha); }[/code] That will spit out a random string. Is that what …

Member Avatar for Moschops
0
110
Member Avatar for strungoutfan78

Variable sized arrays are not supported in ISO C++ (enabling warning high enough in g++ will produce this error as well). You can use the solution posted by caut_baia to get what you want or you can use an enum [code]enum { SIZE = 10 }; int foo () { …

Member Avatar for strungoutfan78
0
399
Member Avatar for kra9853

The modulus operator is an integer operation. It returns to you the remainder after [i]integer[/i] division. Dividing by a floating point number gives you an exact floating point value (no remainder) so the operation makes no sense. If you want a random floating point value in a particular range I'd …

Member Avatar for kra9853
0
168
Member Avatar for techningeer

[icode]#include <iostream>[/icode] Drop the .h Oh, and use either[code]using std::cout;[/code]or[code]std::cout << "...";[/code] or you will get more errors related to sytax.

Member Avatar for techningeer
0
397
Member Avatar for anurag.barman

I'd suggest you distill this a bit until you get things working. Then put the pieces together as they are verified. FOr instance, the fact that you have the following sequence of events[code]data = (char *) malloc(size ); data = (char *) arg ;[/code]means to me that you have be …

Member Avatar for L7Sqr
0
116
Member Avatar for mitrious

What happens when [icode]std::numeric_limits<int>::max() == RAND_MAX[/icode]? You'll never actually enter any of your code segments since [icode]if(n > RAND_MAX)[/icode] can not ever be true. In order to be able to return a value larger than RAND_MAX (without worrying about overflow) you will need to return a long or long long …

Member Avatar for pseudorandom21
0
1K
Member Avatar for Lord_Migit

Pointers are interesting (as you've realized). There is no way to tell from a pointer whether it should be deleted or not. For instance consider the following[code]Object o, * optr = &o; // Some place later in your code std::vector<Object *> optrs; optrs.push_back(optr); // this should definitely *not* be deleted …

Member Avatar for Lord_Migit
0
145
Member Avatar for XA04

To add to what arkoenig mentioned, you can also provide an initialization list to your array. For instance:[code]struct Foo { int x; Foo(int i) : x(i) {} }; // Now you can do Foo foos[3] = { 1, 2, 3 }; // initializes with Foo(1), Foo(2), Foo(3)[/code]This is limited in …

Member Avatar for rxlim
0
707
Member Avatar for crapgarden

It might be the case that a shipCost is represented as an int but it might not. The fact is that the types are not the same (regardless of the underlying representation) and should be treated that way.

Member Avatar for crapgarden
0
167
Member Avatar for ChaseRLewis

It might have something to do with the way you are determining your index. I'm sure sin implementations vary widely across platforms and depending on the chip support underneath, but if I run a simple test where I do the following:[code]for( int i = 0; i < 10000; ++i) for …

Member Avatar for mike_2000_17
0
2K
Member Avatar for prtipal.singh88

The best I can tell you is that you should look at the source of something similar to what you want to mimic ([URL="http://www.virtualbox.org/wiki/Downloads"]virtualbox[/URL]). If this is a short-term school project you have a long road ahead of you as this is - in every situation - a non-trivial endeavor.

Member Avatar for L7Sqr
0
118
Member Avatar for pinky khan
Re: c++

This is generally platform specific. You haven't specified what platform you are using and whether or not you intend on using existing libraries or not.

Member Avatar for JSPMA1988
0
108
Member Avatar for lochnessmonster

A simple example of when this is useful is when you are mixing output to stdout and stderr. stderr is not buffered and stdout is so it may be the case that printing to stdout will show up at unexpected locations if it is not flushed. [Edit] For example, on …

Member Avatar for lochnessmonster
0
147
Member Avatar for elsiekins

You can use getchar as follows [code=c]#include <cstdio> #include <string> #include <iostream> int main () { char c = getchar (); std::string s(1,c); std::cout << "Entered: " << s << std::endl; return 0; }[/code] That [i]will[/i] leave the remainder of the input unused so if you intend to read from …

Member Avatar for elsiekins
0
176
Member Avatar for petero_l

It might behoove you to break that functionality into separate functions. For instance[code]case '1': do_stuff_1_here (); break; case '2': do_stuff_2_here (); break;[/code] It helps maintain readability and understanding.

Member Avatar for petero_l
0
253
Member Avatar for Fumomo

I'd suggest you convert your current structure to a [code]std::map< std::string, int >[/code] and use that to handle your duplicates. The logic would flow something like:[code]// pseudocode void convert(array, map) { for name,value in array { map[name] += convert_to_int(value) } }[/code] You can then output to file by iterating over …

Member Avatar for drkybelk
0
125
Member Avatar for stankefa

Tracer bullets are always useful in a case like this. Consider the following updates: [code=c]X (const X& right) : myID(++id) {cerr << "Copied " << id - 1 << endl;}[/code]and[code=c]X f (X x1, X& x2) { cerr << "Enter f" << endl; x1 = x2; cerr << "Exit f" << …

Member Avatar for Fbody
0
198
Member Avatar for sahil1991

You can look [URL="http://http://www.cplusplus.com/reference/iostream/streambuf/"]here[/URL] for streambuf and [URL="http://http://www.cplusplus.com/reference/iostream/filebuf/"]here[/URL] for filebuf. Please follow-up with pointed questions regarding the above.

Member Avatar for L7Sqr
0
58

The End.