6,741 Posted Topics
Re: Lose the static qualifier. extern should be placed on the array in the header file to ensure that it's a declaration. Then include file1.h in both file1.c and file2.c. Make sure that the code to fill the array is called first if you define it in file1.c. | |
Re: >^^^does that mean the array size is 100 and the first element is equal to 0? An array of size 100 and all elements are initialized to 0. If you privide an initializer list and there aren't enough values, all remaining elements are initialized to the default value T() where … | |
Re: In a set, the value is the key. In a map, the key and value are distinct. | |
Re: >I've got to implement Prolog in C++ for an assignment. Let me get this straight. You're new to C++ and you've been given an assignment to write a Prolog interpreter in C++? I find that hard to believe. It's easier to believe that you slacked off for most of your … | |
Re: What happens if you try to use a standard container, such as map? Same errors? Or is it specific to the extended containers and algorithms? | |
Re: I've seen excellent attempts to get other people to do homework, but this isn't one of them. Thread locked. | |
| |
Re: >printf( msg ); Bad idea. If msg contains any sequences of characters that look like a format modifier, you'll invoke undefined behavior. Do this instead: [code] printf( "%s", msg ); [/code] >sometimes some of threads freezes Sounds like a deadlock to me. It also sounds like a perfect opportunity to … | |
Re: >Is it just defining the number of characters assigned for the message? Yes. | |
Re: Show your attempt. Tell us what you learned while doing it. Otherwise, we'll assume that you want a handout and nobody will help you. | |
Re: >The base class is point . Inheritance isn't the right solution for point. A shape is not a point. A shape has one or more points, so containment is a better solution. point should be a stand-alone class. I really hate the shape abstraction as a means of introducing inheritance, … | |
Re: >I need an example of how its done in C++ Inheritance in C++ is far more complicated than Java; it would take me too much space to do it justice. You would be better off getting a good book on the subject. Thinking in C++ covers it well from what … | |
Re: Well, do you understand what the frequency and mode are? The mode can be easily found once you've obtained the frequency, and the frequency is trivial with the standard library: [code] #include <cstddef> #include <iostream> #include <map> #define length(x) (sizeof (x) / sizeof *(x)) int main() { int a[] = … | |
Daniweb's IRC channel is boring, and it's everybody's fault. The more people that go there, the more fun it will be, so I order everyone to get an IRC client (because Java clients suck) and go to irc.daniweb.com, port 6667 and join #daniweb. This goes double for people who visit … | |
Re: Don't post that much code without code tags, and don't bump your thread after just an hour. Both are incredibly rude and don't encourage people to help you. | |
Re: >if( first >=0) This is never true since you initialize first to -1. Initialize it to 0 and the vector should work more like you expect. | |
Re: >Anybody can help to explain why "m_line.replace(idx, m_search.size(), replace);" doesn't compile in cygwin Perhaps because replace isn't a valid third argument? How about: [code] m_line.replace(idx, m_search.size(), m_replace); [/code] | |
Re: Yes, but not with straight C++. You're looking at operating specific API calls. | |
Re: >Would both abstract and static be correct answers? No, abstract is the correct answer. static only means that a nested class doesn't designate an inner class. | |
Re: >This is not likely ever to be true. You mean false? I'd say it's highly likely to be true since EOF must be a negative quantity and characters gathered from a narrow stream must fit within an unsigned char. Fortunately, the other half of the condition will cause the loop … | |
Re: >what will happen if we free the same memory two times in C Undefined behavior. Anything could happen. | |
Re: >display teh string "HELLOWORLD" in ascending style Riiight. Care to explain what you mean by "ascending style"? >what does %.*s stand for??? The . is a field width modifier. Any value after it is how many characters of the string should be printed. The * is a placeholder for a … | |
Re: I answered your question in the original thread that you asked it, but for convenience I'll copy the answer here: >Can you please clarify the difference between Sequential Access Files and Random Access Files? Humor my love for simile. A sequential access file is like traversing a linked list, while … | |
| |
Re: [code] string operator+ ( const string& s, const Dan& d ) { return s + d.toString(); } [/code] Since Dan doesn't have a suitable conversion to std::string, you also would need to provide another operator+ with the commutative operation: [code] string operator+ ( const Dan& d, const string& s ) … | |
Re: The most common method by far is TCP/IP or UDP using sockets. Unfortunately, that's a rather broad topic. You can get a bunch of good info to get started [url=http://www.ecst.csuchico.edu/~beej/guide/net/]here[/url]. | |
Re: Lines in blue are the changes I made: [code] [COLOR=Blue]#include <vector>[/COLOR] #include <iostream> [COLOR=Blue]using namespace std;[/COLOR] class Object { private: short data; public: Object(){data = 1;}; }; [COLOR=Blue]typedef Object* pObject;[/COLOR] class Container { private: vector<pObject> v; public: Container(){v.reserve(1);}; void Add_Object(pObject o){v.push_back(o);}; }; int main() { [COLOR=Blue]Container theContainer;[/COLOR] theContainer.Add_Object( new Object() … | |
There's a link to list all active users on Daniweb from the forum nexus. It would be nice to also have that feature for each individual forum, or at least a way to sort by forum. Would that be too difficult to implement? | |
Re: >What a kind of comparision do we do? It does a lexical comparison using the integral value of a character: [code] int i = 0, j = 0; while ( a[i] == b[j] ) { if ( a[i] == '\0' ) return 0; ++i; ++j; } if ( a[i] < … | |
Re: Sorry, but I can't be bothered. Why don't you write it for me then post it in my name? In case that was too subtle for you, I'm basically saying that without proof of effort on your part, nobody is going to help you unless your problem is dead easy, … | |
Re: >Are there any good solution Yes, Dave's solution is a good one. Your code will fail because string literals can't be modified, and strtok modifies the string you pass to it. Changing cmd to an array fixes the problem. Just in case you didn't catch it, remove the parts in … | |
Re: >cout << product; Replace that with this: [code] cout << product << '\n'; [/code] | |
Re: >the instructor told me there are two mistakes in this Design or implementation? Design-wise, the use of integers as position markers is silly, pointers to nodes would make more sense. It also suggests that the list is always in a certain "state" where to get to the front of the … | |
Re: Is this homework? If not, what kind of research did you do before coming here asking for code? If so, why are you asking [b]us[/b] to do it for you? >ohw to open closed thread You ask a moderator to do it for you (preferably me, since I closed it … | |
Re: >First, how do you feel about operator overloading? It's a frivolous feature that isn't really needed, but it sure is a convenient feature when used intelligently. For example, the iostream library certainly makes streams easier to use by overloading operator<< and operator>>. String comparisons are more intuitive by overloading the … | |
| |
Re: Your StripVowels is way overkill. At least it would be if it weren't filled with type mismatches and unnecessary member function calls: [code] #include <algorithm> #include <iostream> #include <string> using namespace std; bool is_vowel ( const char c ); void StripVowels ( string& s ); int main() { string s; … | |
Re: >Can the main() call be embedded within a class? You need to make the distinction between a function declaration, a function definition, and a function call. What your example does is declare a member function with the same signature as the global main. However, it's [b]not[/b] the same function as … | |
Re: [url=http://www.ecst.csuchico.edu/~beej/guide/net/]Clickie here for the best free tutorial on sockets[/url]. And please don't come back here bitching that it's not C++. The concepts are identical, and free stuff is never exactly what you want. | |
Re: >Yes but how do I change that? I would think it would be obvious: [code] char [COLOR=Blue]*[/COLOR] getstring (char strquestion[255]) [/code] >I'm sorry? What do you mean? sprintf returns the number of characters printed, not a string of any sort, which is what your use of getstring suggests. You could … | |
The game is simple. Search a forum (preferrably one that you don't visit often) and post a quote from that forum that you find amusing, informative or just plain cool. Use of the search feature is encouraged. Rules: 1) All quotes must include the name of the original poster. 2) … | |
Re: >how i can run vc++ 6 program in vc++.net Just a minor nit. "How I can" is a statement, "How can I" is a question. And to answer your statement, if the old project isn't being updated, just create a new project in VC++ .NET and transfer your source files. | |
Re: >Please tell me there is an easier way than this Put your data into a structure, create an array of structure objects, and sort that: [code] struct course { string name; int hours; char gpa; char grades; }; course courses[50]; ... bsort(courses, cnt); [/code] Then you need to change bsort … | |
Re: >Microsoft Visual C++... great IDE, very easy to use, but costly... The standard edition is only $99US. Hardly costly unless you're a student with no cash. Though Dev-C++ seems to be a favorite among the freebies. | |
Re: The measurable, countable, or comparable property or aspect of a thing. | |
Re: I hate to break it to you, but that's not C. | |
Re: [code] #include <iostream> using namespace std; int main() { int a[5][5] = { {1, 2, 3, 4, 5}, {6, 7, 8, 9,10}, {11,12,13,14,15}, {16,17,18,19,20}, }; // Row major order for ( int i = 0; i < 5; i++ ) { int sum = 0; for ( int j = … | |
![]() | Re: If the date is invalid you do this: [code] date = NULL; [/code] Then you proceed to do this: [code] return *date; [/code] That would be dereferencing a null pointer, which is illegal and highly likely to crash your program. Of course, that entire function is one big red flag. … ![]() |
Re: Can you post your code? Preferrably something small that still exhibits the problem. |
The End.