1,296 Posted Topics
Re: Of course, all possible in C++ ;) That's an improvisation: [code=cplusplus] /// suite.h (class Suite definition) class Suite { public: Suite() {} Suite(const Suite& suit):value(suit.value) {} static const Suite Hearts, Clubs, Diamonds, Spades; /// that's all, add some methods... const string& str() const { return value; } /// add some … | |
Re: All except '\r' and (may be) quotes ;) Do you really want to study C i/o basics on DaniWeb forum? Better search for a good C i/o tutorial. There are lots of good links... | |
Re: A day ago csurfer's algorithm solved the problem. That's "pipelined" version: [code=c] int i, j = rand()%20; for (i = 0; i < 20; i++) array[i] = (i != j)*(rand()%9 + 1); [/code] In addition: it's impossible to add [i]another level of randomness[/i] by random shuffles or other tricks while … | |
Re: >not many people will ever touch something like a 4-bit machine or any other sort of setup. None the less there were supercomputers with 6-bits and 9-bits (or may be 12) bytes ;) Moreover, I have seen a real computer with various byte widths (every 6-th byte was shorter than … | |
Re: >short answer: static arrays are allocated when the function is called... Short remark: [b]static[/b] arrays are allocated [b]before[/b] the first call of the function. However no static arrays in OP snippet. Please, be more thoroughs in terms using. | |
Re: Container iterator is an analog of a pointer, you must derefence it to get a value: [code] cout << *myIterator << endl; [/code] It's interesting, what's your [i]temp[/i] variable?.. | |
Re: >I believe static libraries are included within the executables... The linker searches static libraries for object (compiled) modules needed to built an executable. For example, suppose you build a static library from v2.cpp and v3.cpp source modules then distribute it. Let your client links the code using v3 features only … | |
Re: [QUOTE=seemant_sun;885769]void openfile(char *,FILE**) what does double stars indicates[/QUOTE] The second argument type is a pointer to a pointer to FILE type. Didn't you understand what's a pointer? Evidently this function returns FILE* pointer via this argument. What's a strange perversion... | |
Re: Probably you want a pointer which points to the minimal data value. In actual fact it's (as usually) senseless operation to compare pointer values. Moreover, the result of pointers comparison is well-defined only if two pointers points to the same array. If so, compare data values, not pointers. Save pointer … | |
Re: If you wrote a text line on a paper sheet, you can't insert anything in this line without a rubber and rewriting or a glue and scissors. A file storage looks like a paper, however it's impossible to cut then to glue up your hard disk tracks. More safe procedure: … | |
Re: If the input file looks like in post#6, why '-' line terminator (see Lerner's post)? However the code has more serious defect(s). You should make [icode]char Grade[2][/icode] and change Grade input field size to 2. It's impossible to get 1-char string into 1-char field (see Vernon's explanation) so after [code] … | |
Re: Too many problems on a single (and simple) program case is a symptom of bad design solution. Evidently in that case you need different data structure. You want dynamically defined data structure size - but an array size in C++ is a compile-time defined (constant) expression. You want to remove … | |
Re: Why strncat? Make a single (expected) string by a single snprintf call. What's a problem? | |
Re: It's possible to convert enumeration value to int but no an implicit reverse conversion. That's why [icode]currentMonth = currentMonth + 1[/icode] expression is wrong. More precisely, the right side is legal subexpression (treated as [icode](int)currentMonth + 1[/icode] and has int type) but no [b]implicit[/b] [i]int to months[/i] conversion and the … | |
Re: [QUOTE=guest7;887344]I have a c++ program which uses the api's of a utlitiy. As per the document I have to include the path of binaries for the utility in my code. I am not sure why that is required and how to inlcude that. Any help is appreciated Thanks[/QUOTE] Are you … | |
Re: Fortunately, you can't define these weird macros. Macro definition consists of [b]tokens[/b] (valid C++ lexical units) - it's so called [i]token-string[/i] in the C++ standard. In other words, it's not an arbitrary sequence of characters. No such token as a single quote mark in C++. It starts a string literal … | |
Re: [code=cplusplus] bool isReverse(const std::string& s1, const std::string& s2) { std::string t(s2); std::reverse(t.begin(),t.end()); return s1 == t; } [/code] | |
Re: 1. Use code tag properly: [noparse][code=cplusplus] your code [/code][/noparse] 2. [icode]int main()[/icode], never write [icode]void main()[/icode]! 3. What's your test plan? What did you want to achieve with this code? 4. What's your problem now? If you have a run time error, what's this error? No explanation... Well, that's the … | |
Re: [QUOTE=deostroll;886400]Your mother board has a processor! So definitely they should have registers. And I am pretty sure of the registers part, because I just wrote some assembly instructions and executed them...in vc++ 6.0 [CODE]asm { //your asm code goes here. }[/CODE][/QUOTE] Remember these three interesting facts: 1. Some processors have … | |
Re: Try to append [b]LL[/b] suffix to long long constants. | |
Re: >the program encrypts the text at a rate of about 5000 characters per second on a 500mhz Intel Pentium 3 running windows xp pro. It looks like an extremely low speed. I think that's a lower bound of a "good" speed (for more complex than DES chiphers): ~5-10 Mbytes/second. Try … | |
Re: Thanks God, -> and . have the same precedence and associativity. The OP example with a pointer parameter works fine in VC++ 2008. Diagnosis: insufficient info ;) | |
Re: Of course, the original post is extremely ill-formed. However at least one defect arrests attention: sort_names function is wrong. Sorting loop index is out of range: [icode]names[j+1][/icode] refers to inexisting string element when j == size-1. To OP: don't try to start this code as is: there are too many … | |
Re: Initialization of class members (except static integral types): [code=cplusplus] class Ob // avoid all small letters names { public: // declare public then protected then private Ob():name("Name") {} // member initializators list ... private: std::string name; // initialize in constructor(s)! }; [/code] | |
Re: Let's look at your Quadratic::operator=(). It's funny but (not indented properly in your code) [code] if (a.pointer == NULL ) pointer = NULL; else pointer = a.pointer; [/code] has exactly the same effect as [code] pointer = a.pointer; [/code] Why if-else? Think a little before coding... However it's a wrong … | |
Re: An ordinar problem with wrong index expression ;) Corrected code (test it! ) : [code=cplusplus] // preferred way to define constants in C++ const size_t digits = 1000; /// max power ~3000 unsigned Dig2N(unsigned power = 1000) { unsigned num[digits] = {0}; unsigned ctr, carry; unsigned length = 1; num[digits-1] … | |
Re: >Its format is a name (including spaces) is 20 characters, then 4 digit number, a space, and a number thats not a set number of characters. Probably it's a wrong line format description (judging by the file contents example the name field has not fixed width). However if it's true, … | |
Re: Back to real OP problems ;) Evidently struct str definition is not complete (moreover: it's incorrect). Where are print and append member functions? Why [icode]string p[/icode] member? Where are copy constructor and operator= (both are obligatory for classes with pointers to dynamically allocated data chunks). Why malloc/free C-function calls instead … | |
Re: absread: What's it: ancient TC non-standard function to read a sector from the HD in native DOS environment. Usage: forget as soon as possible. | |
Re: According to the C and C++ standards [code] int array[....]; [/code] [icode]array[-2][/icode] - wrong expression, because array-2 points to inexisting array element (the only exception: pointer to the 1st element after array end). Therefore we can't dereference it in *(array-2) expression (that's [icode]array[-2][/icode] by definition). Moreover, array-2 value is undefined … | |
Re: Now read why [icode]fflush(stdin)[/icode] is wrong: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351[/url] and how to flush the input buffer in C: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044873249&id=1043284392[/url] | |
Re: >If i use float instead of double, i get the answer 25.628401 (which is wrong... 1. It's the same question as [i]Why Cessna 182 can't be so fast as F-22?[/i]: float data type has precision ~6-7 decimal digits only... 2. and 3. "dye" means [b]dye[/b]: memory cells allocated (as usually … | |
Re: [code] for (int i = 0; i < 20; i++) [/code] | |
Re: may be it helps to improve your code: [code=cplusplus] #include <string> #include <fstream> #include <cctype> #include <vector> std::string& capZ(std::string& s) { int c; std::string::size_type pos = 0; do { while (pos < s.size() && (c = s[pos]&0xFF, isspace(c))) pos++; if (pos == s.size()) break; if (s[pos] == '.') pos++; else … | |
Re: How about - 30 milliseconds to create a text file with 100000 lines (10 Mb) - 400 milliseconds to scan 100000 lines, search pattern and call a function on AMD 5000+/Windows XP/VC++ 2008 release with standard i/o streams only? ;) PS. Of course, it's not an optimal solution - no … | |
Re: No opened stdin and stdout streams in Win GDI applications (null pointers). You can't use scanf and printf functions in the program. See, for example: [url]http://blogs.msdn.com/oldnewthing/archive/2009/01/01/9259142.aspx[/url] | |
Re: What's this input source? What's the output target? | |
Re: It seems you don't verify your list interface. For example: 1. What's a role of the 1st insert_start parameter? You overwrite its value in the 1st statement of the function body then create new node... 2. On the contrary, insert_end uses its parameter if global variable head is not equal … | |
Re: Let's start from the real code... See for loop condition: [icode]i >= 6[/icode]. In other words, [i]while i is greater than or equal to 6[/i]. The initial i value is 0... | |
Re: What's an excited title for help request: [b]I don't know!![/b]... Next time try to invent more sensible phrase... It's a well-known ;) fact that [code] lcm(a,b) = (a/gcd(a,b))*b [/code] where [i]gcd[/i] means [i]greatest common divisor[/i]. Euclidian algorithm for computing gcd - see: [url]http://en.wikipedia.org/wiki/Euclidean_algorithm[/url] It's so easy... Don't use global variables … | |
Re: I can't understand why your brutal force algorithm is so expensive (apropos, where is this algorithm? ;)) Numbers in range 1..1000000 have less than ~65 divisors. It's so easy to get all divisors by brutal force test (n%k == 0) then (or on the fly) to multiply some tens of … | |
Re: Besides that you don't understand a role of stdafx.h in Visual C++. Place all standard header includes in stdafx.h (not in main module)! Read about pre-compiled headers in Visual Studio help... | |
Re: Better try to read this forum rules before 6th of June: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] | |
| |
Re: Line #172 and below: statements outside function body... Where is this function header? | |
Re: [code=cplusplus] char* arr = new char[...]; f.read(reinterpret_cast<char*>(arr), ... [/code] Why reinterpret_cast?.. | |
Re: Try much more simple and effective solution: [code=cplusplus] namespace { // Locals: const std::string card[] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; const std::string suit[] = { "Hearts", "Diamonds", "Spades", "Clubs" }; } // End of Locals const std::string& randCard() { … | |
Re: Alas, your code is wrong. When you got the last word file.eof() is not true! Only the next [icode]file>>Word[/icode] expression changes the file stream state to eof (and does not read anything). After that all operations on the file stream are suppressed until you clear() the stream. That's right file … | |
Re: [quote]The funny part is: all this doesn't happens in the line previous to this. That is perhaps because of your compiler's smartness, it doesn't promote -1 to int but demotes x to a int.[/quote] 1. Probably you mean [i]doesn't promote -1 to [b]unsigned[/b] int[/i]... 2. All this [b]happens[/b] in [icode]int … |
The End.