6,741 Posted Topics
Re: 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 … | |
Re: 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: … | |
Re: [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. | |
Re: 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 … | |
Re: 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++) { … | |
Re: 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 … | |
![]() | Re: [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 … |
Re: 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] | |
Re: [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). … | |
Re: [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 … | |
Re: [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 … | |
Re: [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 … | |
Re: [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. | |
Re: [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 … | |
Re: 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 … | |
Re: [B]>can u explain it in an easy way... i mean the complements[/B] Bits go flip floppy. | |
Re: Sorry dude, I have a hard time believing that any legitimate school project would require you to make a robust keylogger. | |
Re: 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 … | |
Re: 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. | |
Re: [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 … | |
Re: 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 … | |
Re: 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. | |
Re: [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? | |
Re: 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 … | |
Re: 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. | |
Re: [B]>How come 012 gives me 1010??[/B] 012 is 10 in octal, which has a bit pattern of 1010. | |
Re: Are you using an installer or just copying the files manually to each new machine? | |
Re: [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. | |
Re: 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] | |
Re: [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]. | |
Re: 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 … | |
Re: [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. ;) | |
Re: [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. | |
Re: [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. | |
Re: 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. | |
Re: [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<< … | |
Re: 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] | |
Re: [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? | |
Re: [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 … | |
Re: [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. | |
Re: [B]>heeeeeeeeeeeeeeeelppppppppppp plz[/B] Help with what? Cheating on your homework? Sorry, we don't do that here. | |
Re: [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 … | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: [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? … |
The End.