6,741 Posted Topics

Member Avatar for hnf1991

You have two options: [LIST=1] [*]Read a line of input, parse it, and determine whether it matches your program's expectations. If not, print an error and request input again until you get what you want. [*]Use a non-standard, non-portable library to read raw input from the keyboard. With this you …

Member Avatar for Dave Sinkula
0
87
Member Avatar for Donnovan

You're forgetting that function parameters are always passed by value in C. If you want to specify an output or reference parameter, you use pointers: [code] #include <stdio.h> #include <stdlib.h> typedef struct { char *vnaam; char *anaam; int leeftijd; } persoon; persoon *q, p1; void drukaf(persoon p){ printf("\nVoornaam: %s\n",p.vnaam); printf("\nAchternaam: …

Member Avatar for Donnovan
0
111
Member Avatar for GyanPP

[B]>To specify a 64-bit integral (long long) type, use the LL or ll suffix.[/B] However, note that [ICODE]long long[/ICODE] is not standard C++ yet (C++0x is nearing completion though), so you might encounter either complete failure or a difference in the details with various compilers.

Member Avatar for GyanPP
0
147
Member Avatar for imolorhe

Q: Do you know how to do it on paper? (a) No: Go figure that out before trying to write code. (b) Yes: Show us your code, and be more freaking specific about what problem you're having. Since you didn't post any code, I'll assume your answer to the question …

Member Avatar for xavier666
0
176
Member Avatar for pac-man

When you changed int to T in the iterator parameters, they became dependent types. You need to specify that iterator refers to a type name: [code] template <class T> int number( T n, typename vector<T>::iterator start, typename vector<T>::iterator end) { int count = 0; for(start; start != end; start++) { …

Member Avatar for pac-man
0
231
Member Avatar for kavourdoukos

C++ doesn't support non-constant array sizes. You need to simulate an array with a pointer and dynamic memory: [code] // Simulate an array of pointers to classA classA **array = new classA*[size]; // Populate the elements for ( int i = 0; i < size; i++ ) array[i] = new …

Member Avatar for mrnutty
0
123
Member Avatar for san_fran_crisko

[B]>There seems to be a lot of conflicting opinions on whether one >should learn C before C++ or its OK to go straight in to C++?[/B] Anyone who claims that one is a prerequisite for the other is misinformed. You can learn them in either order, just pick the language …

Member Avatar for Narue
0
286
Member Avatar for Nikhar

Be careful with your recursive functions. In your case, delete1 tries to access a dangling pointer because your if chains aren't all connected. Try this instead: [code] void delete1(node *&tree, int data) { if(tree->data==data) delete2(tree); else if(tree->data<data) delete1(tree->right,data); else if(tree->data>data) delete1(tree->left,data); } [/code]

Member Avatar for Nikhar
0
126
Member Avatar for johndoe444

[B]>Prefer classes to structs.[/B] Do you have any particular reason for that guideline? I ask because I've met too many people that have some unreasonable idea of classes being more OO than structures. :icon_rolleyes: The only difference between structures and classes is default visibility (public for structures, private for classes). …

Member Avatar for mrnutty
0
135
Member Avatar for asm2hex

[B]>Maybe this will give a clearer meaning of what I'm trying to do.[/B] strtok doesn't make a copy of the token, it modifies the original string by adding a null character at the end of each token and then returns a pointer to it. Every pointer in token, and consequently …

Member Avatar for Narue
0
104
Member Avatar for jakesee

[B]>What I don't understand is when did Apple and Orange instances get created?[/B] They didn't. You're invoking undefined behavior because _mInstance is a null pointer. However, neither squeeze nor cut access non-static data members, so there's a good chance that both functions will run properly. Here's an example of the …

Member Avatar for jakesee
0
485
Member Avatar for xavier666

[B]>You could maybe do it by building a linked list of character variables?[/B] That's a little excessive both in terms of space and time. Let's assume you use pointer links for the nodes, that adds the size of a pointer to each character in the "string". It also adds the …

Member Avatar for Narue
0
426
Member Avatar for pac-man

[B]>Shouldn't this be an error?[/B] It [i]is[/i] an error. Just because it doesn't blow up spectacularly when you test doesn't make it any less wrong.

Member Avatar for pac-man
0
125
Member Avatar for CppBuilder2006

[B]>I didn't insult.. I said what I thought.[/B] Just because you're being honest doesn't mean you're not being insulting. You have to be pretty self-centered to suggest that [i]we're[/i] not helpful due to [I]your[/I] inability to ask a smart question and have reasonable expectations. Whether I know the answer to …

Member Avatar for CppBuilder2006
-2
583
Member Avatar for imso

It looks like you're mixing solutions, and you added too much fluffy code without getting a solid solution first. [B]>char binaryinput[8];[/B] If you're going to print binaryinput as a string later, you need to leave room for a null character at the end. [B]>printf("\tPlease enter an 8-bit binary bits:");[/B] If …

Member Avatar for Dave Sinkula
0
214
Member Avatar for caroll
Re: tilt

[B]>can u explain it in an easy way... i mean the complements[/B] Bits go flip floppy.

Member Avatar for caroll
0
142
Member Avatar for HolstebroTS

Sorry dude, I have a hard time believing that any legitimate school project would require you to make a robust keylogger.

Member Avatar for HolstebroTS
0
77
Member Avatar for surfer2009

For each object you print using cout, figure out the type and put it in a format string. String literals go into the format string as is, and in order. In your case, the types are int (for x) and double (for the return type of pow), so you would …

Member Avatar for Narue
0
95
Member Avatar for IT seeker

Seriously? At 25 posts I would assume that you know how hostile we are toward leeches. If you really haven't experienced it, I'll be happy to verbally abuse you until you understand that we're not here to be your code slaves.

Member Avatar for Narue
-1
103
Member Avatar for ireimaima

[B]>Hint, initialize your variables.[/B] It's not that simple. An untrained eye could easily say that the variables [i]are[/i] initialized prior to use. [B]>for(int i=0, sum=0; i<=4; i++)[/B] You're actually defining a new sum variable here, not initializing the parameter named sum. The new variable hides the old one, and any …

Member Avatar for ireimaima
0
2K
Member Avatar for techevo

Since you didn't post any code at all, I'll have to dig out my crystal ball and divine the source of your problems from thin air. Many people would call this pulling complete guesses out of my ass, but the possibility remains that I'm actually psychic. I bet your code …

Member Avatar for Narue
0
85
Member Avatar for sam1

One might assume that the Text property refers to a string, which doesn't make sense to compare with an integer. You probably need to convert your string into an int, then compare it to 0.

Member Avatar for sam1
0
80
Member Avatar for gerard4143

[B]>int main(int argc, char**argv)[/B] If you don't use the command line arguments, why include them? [B]>exit(EXIT_SUCCESS);[/B] Do you have any particular reason for calling exit rather than simply returning?

Member Avatar for jonsca
1
114
Member Avatar for Hofik

I'm not sure I understand what your problem is. After fixing the immediate bugs, the program works for me. All of the examples you gave produced what I understand to be the correct output. Following are the bugs that caused a crash when I tried to run your code as …

Member Avatar for Hofik
1
87
Member Avatar for fadia

The base case is when you want the recursion to stop going deeper and return back up the chain. In your case it's probably when n is less than zero.

Member Avatar for fadia
0
132
Member Avatar for bhas_purk

[B]>How come 012 gives me 1010??[/B] 012 is 10 in octal, which has a bit pattern of 1010.

Member Avatar for bhas_purk
0
83
Member Avatar for sodak
Member Avatar for sodak
0
146
Member Avatar for Androggles

[B]>I am using Live Messenger as an example[/B] Riiight. So what file are you [I]actually[/I] trying to delete if not Live Messenger? Your example is a smidge suspicious.

Member Avatar for Androggles
0
159
Member Avatar for JoaoC
Member Avatar for Carrots

A stringstream is still a stream. Just do it the same way you would with cin: [code] string key, value; while ( buffer>> key && getline ( buffer, value ) ) mapname[key] = value; [/code]

Member Avatar for Narue
0
188
Member Avatar for Enhancelogic

[B]>but I was wondering if you could explain it in layman's term?[/B] If [ICODE]greeting.size()[/ICODE] is 5, spaces will be "*****". If [ICODE]greeting.size()[/ICODE] is 3, spaces will be "***". The number of asterisks matches the number of characters in [ICODE]greeting[/ICODE].

Member Avatar for mrnutty
1
299
Member Avatar for kevinkace

Here's an example that shows your most immediate problem: [code] #include <cstring> #include <iostream> void foo ( char *p ) { p = new char[4]; std::strcpy ( p, "foo" ); } void bar ( char **p ) { *p = new char[4]; std::strcpy ( *p, "bar" ); } void baz …

Member Avatar for kevinkace
0
110
Member Avatar for samsons17

[B]>toupper() will tell you if the letter is upper case >tolower() tells you if the letter is lower case [/B] You mean isupper and islower. Well, toupper and tolower will tell you too, but it's a pretty fair bet what the result will be. ;)

Member Avatar for mrnutty
-2
175
Member Avatar for destroyed

[B]>i tried so hard but didnot find it yet[/B] We're do-it-yourselfers here. You'll find that instead of giving you code, we'll tell you that if you can't find it, you should go write it yourself. That's how it works in the real world.

Member Avatar for Narue
0
124
Member Avatar for xavier666

[B]>Is it possible my compiler is non ISO C standard?[/B] Seeing as how you're compiling as C++ rather than C, I'd say that's a fair assumption.

Member Avatar for Narue
0
173
Member Avatar for gedas

Did you check your handy C++ library reference? Because it's all explained there, and a more specific question than "can you tell me everything I want to know?" is likely to encourage high quality answers.

Member Avatar for gedas
0
138
Member Avatar for bigsurya

[B]>Why do we overload operators ?[/B] Syntactic sugar. It all becomes clear when you think about a case where the overload is vastly less awkward than the alternative: [code] #include <iostream> #include <string> int main() { std::string hello = "Hello"; std::string world = "world"; // With overloaded << operator std::cout<< …

Member Avatar for Narue
0
93
Member Avatar for rmawatson

The compiler doesn't like the first example because you're making an implicit constructor call using an argument type that isn't expected. It has nothing to do with the semantics of casting. This would fail with the same error: [code] XDeviceMotionEvent motionEvent ( xEvent ); [/code]

Member Avatar for Narue
0
245
Member Avatar for serra01

[B]>I am a diploma holder that's why I am saying this thing.[/B] Proof that a diploma doesn't mean you know what you're talking about. I noticed a snipped link in your post. Are you a spammer?

Member Avatar for WaltP
-5
73
Member Avatar for johndoe444

[B]>how is the typedef for monthTable working while the statement at line 6 not working?[/B] The typedef is syntactically and semantically correct, while line 6 isn't valid C. Do you know how to declare an array in C? It's pretty easy given your code, just take the typedef and remove …

Member Avatar for Narue
0
80
Member Avatar for UtaChan

[B]>scanf("%d",a);[/B] scanf expects a pointer to the object you want populated, so unless a is already a pointer (which it isn't), you need to pass the address to scanf: [code] scanf("%d", &a); [/code] I suspect that's where your crash is coming from.

Member Avatar for Narue
0
228
Member Avatar for mcuk2001

[B]>heeeeeeeeeeeeeeeelppppppppppp plz[/B] Help with what? Cheating on your homework? Sorry, we don't do that here.

Member Avatar for mcuk2001
-1
96
Member Avatar for daudiam

[B]>I thought u meant that u would be starting the search in that group (perhaps >by posting a similar question there) and post when u got a good answer.[/B] Wow. I can't really come up with a good response to this. But I still feel the need to express my …

Member Avatar for Narue
0
270
Member Avatar for harryhaaren

Static data members aren't defined within the class definition, they're only declared. You need to provide a definition as well: [code] class foo { static int x; // Declaration }; int foo::x; // Definition [/code] The definition should be in your implementation file rather than your header file if you've …

Member Avatar for harryhaaren
0
165
Member Avatar for sree_ec

[B]>If so, how we can free that memory?[/B] Assuming the pointer was dynamically allocated in the function (which it wasn't in the case of foo), you either free it within the function or suffer a memory leak. [B]>since size of a pointer(**ptrtoptr is a pointer) is always fixed? >suppose instead …

Member Avatar for Narue
1
343
Member Avatar for jbarwick

[B]>but because of the "operator ()" the function is trying to compare two pointers.[/B] Congratulations, you've independently discovered one of the reasons why overloading the implicit conversion operator is avoided. You'll notice that the std::string class uses a c_str member function rather than an implicit conversion to const char* for …

Member Avatar for Narue
0
280
Member Avatar for daudiam

For the record, C is defined by ISO, not ANSI. Control of the language standard was taken over by ISO in 1990. The language that everyone refers to as "C89" is actually ISO C90 with the 1995 addendum. So C90 or C95 are more strictly correct (though not as well …

Member Avatar for Narue
0
99
Member Avatar for arpit.mishra

[B]>Can I use an overloaded assignment operator for copying character pointers.[/B] Yes, of course. Just keep in mind that you'll probably need to do more than just copy the pointers themselves. If the memory is dynamically allocated (as I assume it is for you to be asking this question) then …

Member Avatar for arpit.mishra
0
157
Member Avatar for daudiam

[B]>I think getch() is the most primitive input function >of C, on which getchar(),etc. are based.[/B] Such an implementation is certainly possible, but I haven't heard of one in the wild yet. Further, even if an implementation [i]did[/i] exist that used getch as a primitive base for stdio, your statement …

Member Avatar for nezachem
0
147
Member Avatar for daudiam

[B]>Then, how can size_t be the data type of result of the sizeof >operator's execution, when the size of size_t is fixed, and the sizeof >operator returns different sizes for different data types.[/B] How can int hold all of those different values when the size is fixed on an implementation? …

Member Avatar for Dave Sinkula
0
196

The End.