1,296 Posted Topics
Re: The last char in the registryHive buffer after fgets() call is '\n' if it was a well-formed text file. Of course, it's not a part of registry key... | |
Re: Alas, the %s format specificator reads only one word from the stream (for example, it reads from the 1st record Smith only but not Smith Allison. After that your fscanf wants to read integer but gets Allison and returns. The next fscanf starts from the current file position (on Allison … | |
Re: Never define global variables in .h files! You can declare these variables, of course - simply use extern keyword before its type, but define such variables in one and only only cpp file. As usually, there are better solutions than global variables using, but it's the other story. The key … | |
Re: It's a slow O(n*n*n) with not optimal implementation solution. It works (I have a proof of the algorithm correctness): [code=cplusplus] int setRank(const int* a, int n, int* b) { int tot = 0; for (int v, s, k = 0; k < n; ++k) { if (b[k] >= 0) { … | |
Re: See also [url]https://www.securecoding.cert.org/confluence/display/seccode/MSC05-C.+Do+not+manipulate+time_t+typed+values+directly[/url] and [url]http://en.wikipedia.org/wiki/Time_t[/url] | |
Re: No any member (variables, functionc etc) names at run time. Your running (compiled, linked and loaded) program is a block of machine commands and constants - an easy and healthy food for processor(s)... | |
Re: Do you want to know: 1. ...where to buy VC++ Pro or 2. ...how to commit a crime ? | |
Re: 1. Use CODE tags for your code snippet: [noparse] [code=cplusplus] your code here [/code] [/noparse] 2. Try to correct absolutely barbaric text indentation. 3. Invalid file opened check in the loop, must be: [code=cplusplus] if (!fin /*!file_name*/ ) { cerr << "Error: file #" << m << " could not … | |
Re: Must be [icode]char* foo ( const char *msg ) {[/icode], of course ;)... | |
Re: Moreover, never use std::vector instead of plain arrays in time-bounded sections of your codes. For example, see vector/array timing in the bottom of my snippet source: [url]http://www.daniweb.com/code/snippet916.html[/url] | |
Re: As is well known Bloodshed Dev-C++ and Code::Blocks are IDE, not compilers. Dev-C++ is a dead project, so better download and install a very good Code::Blocks IDE with MinGW C++ compiler bundled: [url]http://www.codeblocks.org/[/url] It seems Visual Studio 2008 Express is OK but the author can't select right project parameters (it's … | |
Re: I don't understand: 1. ... your sorting criteria. Values in (columns?) #1, #2, #4 are in increasing order but in #3 in decreasing. Why? 2. You have used a map. What for? | |
Re: Never forget to test end of stream condition (avoid loop forever): [code=cplusplus] const int eof = char_traits<int>::eof(); int ch, n; for (;;) { cout << ">"; cout.flush(); for (n = 0; (ch=cin.get()) != eof && ch != '\n'; ++n) { // process ch as you wish } if (!cin) break; … | |
Re: Incorrect mx/mn assignment logic (think about why). Right solution: [code=c] // don't use float type, use double. double m[3][3] = // dont't use capital letters as var names ...; // it's not a good style double minval, maxval; for (int i = 0; i < 3; ++i) { minval = … | |
Re: Hi the Grand Matematical Conclave... 2x^3 + x^2 is not a part of a LINEAR equation! That's a linear equation: A*x + B = 0 So ask a user to type A then B - that's all, your program is capable to print this equation solution now... | |
Re: Well, let's remember C language (it's almost so called expression language) lexical grammar... Here it is expression part: [quote] C language expression tokens:: Identifiers:: all but sizeof <letter|_>[<letter>|_|<digit>]... ---------------------------------- Operators and punctuators:: one of [ ] ( ) : ? . + - * / % ^ & | ~ … | |
Re: And you have wrong for loop limits in bub_sort... | |
Re: Well, let's start from this forum Announcement: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] | |
Re: Use resize(n), not reserve(n) vector member function. The last one does not initialize vector elements, it only reserved memory for future vector grows. | |
Re: Sorry, I can't understand your question. Binary value... of what? The same counter-question about "to decimal value"... | |
Re: Sorry, but [icode]char* ay[][255][/icode] declares 2D array of pointers to char. Probably, coveredinflies wants to pass an array as a function argument so right example is most likely [code=cplusplus] void foo(char ay[][255] ); [/code] But it's not the same as [code=cplusplus] void foo(char **ay); [/code] A pointer to an array … | |
Re: It's a common practice in C++ to implement Object-C @import semantics via sacramental [code=cplusplus] // Header file started... #ifndef HEADER_NAME_DERIVATIVE_ID #define HEADER_NAME_DERIVATIVE_ID // header contents here... #endif [/code] No special standard features in C++ and C preprocessors to do it. The #import preprocessor directive in MS Visual C++ has totally … | |
Re: It's not only a matter of personal preferences. I have seen codes where [icode]using namespaces std[/icode] provokes names conflict errors storm. Have you noticed that a code with explicit namespace prefixes is not depended of that "personal preferences" of its (future, unknown) users? It's especially concern of this (and similar) … | |
Re: This code is an example of a fantastical C and C++ himera. If it's C, why constructors? If it's C++, why typedefs? Some notes. Let's start from trifles. 1. Try to follow common conventions. You are free in names choice (all but keywords) but as usually all-capitals are reserved for … | |
Re: Better see: [url]http://www.partow.net/programming/hashfunctions/[/url] Download freeware C++ hash functions source codes (for std::string) from this site (~3Kb zip): [url]http://www.partow.net/downloads/GeneralHashFunctions_-_CPP.zip[/url] Download PDF chapter 18 (see 18.2, hash function for char arrays) - ~73 Kb: [url]http://www.uow.edu.au/~nabg/ABC/C18.pdf[/url] See also this textbook on C++ programming: [url]http://www.uow.edu.au/~nabg/ABC/ABC.html[/url] Look at hash functions written by professionals... | |
Re: Right now see your problem solution in the neighbours' thread: [url]http://www.daniweb.com/forums/thread139392.html[/url] (especially Salem's advice: random shuffling). | |
Re: Of course, bigInt constructors must be public. But true reason of your troubles is incorrect RSA constructor. That's a right form: [code=cplusplus] RSA::RSA(unsigned m):n(m) {}; [/code] And no need in default constructor... More serious remark: presented RSA constructor does not initialize its bigInt member at all! See what happens: [code=cplusplus] … | |
Re: It seems you try to catch a flea on the dead dog. Better leave in peace this ill-fated sorting. This program can't input data file! Start from the line 36 and totally revise literally every input statement... | |
Re: As usually, a proper typedef helps to clear codes: [code=cplusplus] class Movie { typedef void (Movie::*MovieFunc)(); public: Movie() { f.push_back(&Movie::heHe); f.push_back(&Movie::haHa); } void show(int part) { (this->*f[part])(); } private: void heHe() { cout << "He he" << endl; } void haHa() { cout << "Ha ha" << endl; } vector<MovieFunc> … | |
Re: As far as I know, the only debug assertion in common STL stack container implementations rises when you try to pop an empty stack (Expression: deque empty before pop in Plauger's STL impl.). So revise your algorithm, trace test run step by step with debugger. I think, it's not so … | |
Re: C or C++ program without functions is a nonsense. The 1st step on the right way: try to select code fragments to define usefull functions, for example: [code=cplusplus] int isHere(const int array[], int nelem, int number) { for (int i = 0; i < nelem; ++i) if (array[i] == number) … | |
Re: Try to compress: [code=cplusplus] bool Reverser(std::istream& sentence = std::cin, bool im1st = true) { std::string word; if (sentence >> word) { if (Reverser(sentence,false)) std::cout << " "; std::cout << word; if (im1st) std::cout << std::endl; return true; } return false; } [/code] | |
Re: I have posted the answer yesterday but DaniWeb site discard it (why?). You can't redefine >> operator for bit fields because of no such animal as a reference to bit field in C++ language. Use intermediate int variable then assign it to the bit field - but it's not >> … | |
Re: If you have old Borland's 16-bit compiler, I'm not sure that you can solve your problem with array size constraints. May be try: 1. Select huge memory model. 2. Declare global double* pointers d, d2, d3, d3 and allocate arrays dynamically [code] d = new double[5000]; ... and so on … | |
Re: Better try these functions (don't cram a main story with <<...>> detail): [code=cplusplus] // Homework assignment: add comments... bool ack(const char* prompt = 0); inline bool ack(const std::string& prompt) { return ack(prompt.c_str()); } inline bool nak(const char* prompt = 0) { return !ack(prompt); } inline bool nak(const std::string& prompt) { … | |
Re: It's C++ programming forum. Where is C++ in your post?.. | |
Re: Alas, no any memory blocks in your snippet. You have two uninitialized pointers (both point to nowhere) - memory_block and array_of_floats. So you copy from nowhence to nowhere (with possible access violation, segment faults and other charms). Possible (but, strictly speaking, not conforming to the language standard) solution: [code=c] char … | |
Re: To compile your program w/o errors make some transformations: 1. Replace all float to double (use IDE Replace cmd). Never use float type in scientific/engineering calculations - use only double. 2. Correct two for loop headers [code=cplusplus] for(int s=0;s<g;s++) // add int s declaration [/code] 3. Move standard library includes … | |
Re: [code=c] #include <ctype.h> // or #include <cctype> in C++ if (isascii(c)) {... [/code] It's the same as (c&~0x7F)==0... | |
Re: The last problem: Don't use [icode]ios::app|ios::ate[/icode] flags together: ios::ate suppresses ios::app and truncate the file (don't ask me why now;)). If you want to append new records use ios::app only. If you want to append a record then seek and write at any other place (it's not your case with … | |
Re: 1. Where is a code snippet with this diagnostic message? 2. Presented source is obviously incorrect but it can't print a number. Why strcat? You print name and last_name but one line before strcat appends last_name to name... Never use [icode]cin >> char_array[/icode]! Type a long (>19 chars) name and … | |
Re: Where is it var declaration and initialization code? This pointer variable must refer to FILENAME object. Obviously, it points to nowhere... | |
Re: I don't know (have no needs) how to access floppies on physical level, but: 1. Use [noparse][code]...[/code][/noparse] tags to present your snippets. 2. Use [code=c] if (hFloppy != INVALID_HANDLE_VALUE) /* not if (hFloppy != NULL) - HANDLE is not a pointer! [/code] 3. A very strange, absolutely sensless code: [code=c] … | |
Re: Alas, your program now can't read a file in dynamic or static arrays. See: [code=cplusplus] string line; ifstream data(fName); // Determine number of lines in file int nLines = 0; /* *** You count eof too (no this line but nLines++...) while (!data.eof()) { // string line; // *** move … | |
Re: Nothing criminal with VC++ 2008. Are you sure that the snippet corresponds to the real context? What a compiler are you using? Some tip-comforter - use typedefs in templates: [code=cplusplus] template <class T> class CSplit { typedef std::list<std::vector<T> > ListVector; private: ListVector m_Events; public: bool Event (int Channel, int Message); … | |
Re: 1. I don't understand where the problem starts. You have else without previous if. 2. There are some suspicious fragments in your code. For example, in geoParaFunc you allocated three arrays (see Para... pointers) then overwrite these pointers in [code=cpp] ... Para=geoParaFunc(atNumb[i],Zeq); // function call ... [/code] It's classic memory … | |
Re: 1st part additions: all these chars are control codes for hard copy consoles. Most of them works now (how funny! nostalgic speaker beep after \a). However "\r\n\t" triad is fully actual... 2nd part: it seems STLFilt is potentially useful tool. C++ template diagnostic messages look like nightmares, it's true. Try … | |
Re: What compiler are you using? I can't see any error messages in your post. Why [icode]int pointVal (string s)[/icode] and where is [icode]int HowEasy::pointVal(string s)[/icode] MEMBER FUNCTION definition? Probably, it's a reason of your troubles... | |
Re: Use magical word virtual in [code=cplusplus] class rotatableList { ... virtual void rotate () ... ... }; [/code] and try again... | |
Re: Are you sure it's the right place where lazy pupils engage project teams for free of charge? |
The End.