6,741 Posted Topics
Re: >How EOF(end of file ) works? EOF is simply a macro designating a negative value. It doesn't have to be -1. You can signal end-of-file from the command line with a control character, usually a combination of ctrl+z for Windows systems or ctrl+d for POSIX systems. >while((c=getChar()) !=EOF) Do you … | |
Re: >Is there another way to pause the program with C, without using system("PAUSE"); Sure. Don't run your program in an IDE that isn't smart enough to keep the window open. Run it from the command prompt. | |
Re: [B]>does strcat modify the source paramater at all?[/B] No, it's a pointer to const char. This strikes me more as a fencepost error with your loop index, where it starts at CON_LINES rather than CON_LINES-1. | |
Re: [B]>Is there anyway I can optimize the first one to something that could make my program faster?[/B] Your program is slow because your code sucks. Don't make it suck more by trying to micro-optimize. | |
Re: Those aren't questions, they're coding assignments. You also didn't ask any questions about those assignments, so we're generally going to assume you want someone to do it for you. That's cheating, cheating is not encouraged on Daniweb, and if it's what you want, you're welcome to piss off. Otherwise, here's … | |
Re: Not only is it possible, it's recommended that you use the std::string class instead of C-style strings. I imagine you've tried this already and gotten an error, which prompted you to ask an overly generic question when posting your code and asking a specific question will get your problem solved … | |
Re: I'd use a while loop. But since you can use any loop to simulate the behavior of any other loop, it's really personal preference. | |
Re: [B]>then why there is no error message like >"too many parameters are not allowed"[/B] While a compiler [i]could[/i] warn you at build time about a different number of actual arguments than the format string suggests, it's more complicated than you might think. [B]>do you mean that 1 act as parameter … | |
Re: Well, for starters you used the wrong constructor. Change the definition of wanted_string to this: [code] string wanted_string(original_string, 0, 7); [/code] If that still doesn't work, post a complete program so we can test it. | |
Re: As far as it likely matters to you, they're equally fast. | |
Re: In getid, what happens when r is NULL? | |
Re: The interview is there to determine if you're suitable for the job. If you can't answer the questions to their satisfaction, you have no business working at that company. That's my advice, now if you want something more specific, ask a more specific question. | |
Re: [B]>I want to know the differences in between two?[/B] That's a tough comparison. Can you be a little more specific? [B]>also is this code equivalent[/B] No, the C code has two bugs (an uninitialized FILE pointer, and using char instead of int for the return value of fgetc). The C++ … | |
Re: Separate [i]how[/i]? Do you want them in two different arrays? Do you want to print them on two different lines? Do you want the negative numbers to sing and the positive numbers to dance? Be specific, or don't complain when nobody helps you. | |
Re: Sounds like homework. Why don't you implement all of those algorithms and add logic to count the iterations? It's not hard. I'll even give you a [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx"]link[/URL] to a page with code for all of the algorithms you specified. | |
| |
Re: [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_linklist.aspx"]This tutorial[/URL] might be helpful. | |
| |
Re: Provided you supply either an overloaded operator<, or a comparison predicate in the map constructor, you can use any user-defined type as the key. | |
| |
Re: Floating-point values are imprecise by nature. Trying to compare them for equality is fraught with peril. ;) A fuzzy comparison is usually the best approach. As long as the difference of the two values is less than a certain epsilon, you're good: [code] #include <cmath> #include <cstdlib> #include <iostream> #include … | |
Re: [B]>use a loop.[/B] Obviously. Now do it in an elegant way. ;) | |
Re: [B]>Do you read the DaniWeb news stories?[/B] No. [B]>If not ... what about them doesn't interest you?[/B] There are better sites for news, in my opinion. I treat Daniweb as a forum, nothing more. | |
Re: It's the second one. Your first snippet is [i]two[/i] if statements, one with and one without an else clause. | |
Re: If I understand your question correctly, the compiler is not allowed to reorder struct/class members between access specifiers. You can make the order unspecified like so: [code] struct Vertex { public: Vector3 p; public: Vector3 n; public: Vector3 c; } [/code] | |
Re: [B]>is there any difference between the construction of max heap and min heap??[/B] The only difference is the ordering of your data. In a min heap, the smallest elements have priority, and in a max heap the largest elements have priority. | |
Re: Check your man pages, strrev might actually be present. If not, it's a trivial function to implement for your personal library: [code] #include <string.h> #define SWAP(T, a, b) \ do { T save = (a); (a) = (b); (b) = save; } while (0) char *reverse_string(char *s) { size_t len … | |
Re: The code isn't C++, it's Java. [edit] I'd recommend [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_bst1.aspx"]this site[/URL] for your binary search tree needs. It's largely in C, but the conversion is much easier than from Java. [/edit] | |
Re: [B]>up[/B] Bumping is rude. Now I'll likely ignore all of your subsequent threads. | |
Re: How is that strange? On Windows you didn't touch memory that would cause a critical error, on Unix you did. It means your code is broken. Look for uninitialized pointers and out of bound array accesses. Those are the prime culprits for a seg fault. | |
Re: [B]>I'm getting a warning message while compiling.[/B] Judging by your thread title, the warning is something along the lines of "gets is unsafe". The usual recommendation is to prefer fgets because it allows one to provide a limit to the buffer whereas gets will just happily read until a newline … | |
Re: Have you specified -lbgi -lgdi32 -luser32 as extra libraries? | |
Re: Okay, what do you have so far? It sounds like you're working toward a chained hash table implementation, because the array of linked lists for exact matches is a common collision resolution strategy in hash tables. | |
Re: [B]>In a contact object I store a pointer, which may be for a BCorp or a BPrsn, so I cast it as a (double*).[/B] I can't begin to fathom why you're using double* instead of void* for a safe transient pointer type. Could you explain your reasoning here? | |
Re: There's no operator for a factorial in C++, you need to perform the multiplications manually. You have the right idea though, now it's just a matter of details. Here are a couple of things to consider down the road: [list] [*]This factorial function accepts a signed integer argument, which means … | |
Re: [B]>When I see a thread in C++, and the last poster is "Ancient Dragon" >or "Narue", I just don't bother even opening the thread.[/B] Sounds like a poor strategy if your goal is self-improvement. I try to read all threads that seem remotely interesting ("Gimme teh codez!" are not, by … | |
![]() | Re: [B]>I was just wondering what other people's opinions were.[/B] I wouldn't bother with any kind of marker in the string. The caller clearly knows what radix they want to generate, so generate the string and let them add a prefix (or suffix) if they so desire. |
Re: [B]>What is the use of writing an integer before d or any formal specifiers.[/B] It gives you more control over the output than the defaults. You can override field width, padding, justification, precision, sign display, and whatnot. In this case, you're changing the field width. For example, if you're writing … | |
Re: [B]>char str[31], ch;[/B] Let's start with this common error. EOF is guaranteed to be a negative quantity, but char may be unsigned. getc returns int for a reason, and that reason is to guarantee that EOF is representable regardless of the signedness of vanilla char. [B]>while((ch = getc(fp)) != '\n')[/B] … | |
Re: In other words, you don't know anything about C++ and just randomly pasted the contents of a tutorial into your text editor. What a surprise that it doesn't compile. :icon_rolleyes: | |
Re: Homework is designed to help you solidify your knowledge. If someone else does it for you, you don't learn anything except how to be helpless. So try it first, and if you have problems post your code so someone can help you correct the problems. | |
Re: [B]>I just (wrongly) assumed that all compilers would compile simple increments the same[/B] As with many compiler specifics, it's not quite that simple. Depending on the target processor, different instructions may be deemed more efficient. So you'll see compilers favoring for example add over inc, or lea over both add … | |
Re: [URL="http://www.google.com/search?btnG=1&pws=0&q=how+to+connect+C%2B%2B+to+Database......"]Clicky[/URL]. | |
Re: [B]>but its has its own merits...[/B] There are no merits to gets. [B]>say, the ease of accepting strings...[/B] I've argued this point with authors before (Dan Gookin is one such example), and have yet to hear a sufficiently good explanation of how [iCODE]fgets(s, n, stdin)[/iCODE] is so hard that it … | |
Re: To create an array of objects without initialization, the object type must have a default constructor. The rule in C++ is that a default constructor is generated for you if you don't explicitly define [i]any[/i] constructor explicitly. Your class has a three parameter constructor, so no default constructor is generated … | |
Re: For starters, operation is a double when it should be a char. You also have a rogue semicolon in your final else that ensures the quotient output will always occur. | |
Re: [B]>Can anyone help me on how to display my infix notation with parentheses?[/B] It's simple enough, just print your parens at the operator level for sub-expressions you want to wrap (you probably want to exclude unary operators): [code] template <class Item> void infix(exp_tree_node<Item>* root) { if (root != NULL) { … |
The End.