1,296 Posted Topics
Re: Ooh, yet another grade supersystem... Better try to search DaniWeb for [i]grade[/i]. There are lots of dozens of grade calculation threads (solved;))... | |
Re: Of course, it's possible (under your program "manual" contol). Open file in binary mode. Use fread and fwrite function. See fseek library function to set current write position and ftell to get it. | |
Re: Can you explain what is it: [i]binary search tree sorted with quicksort method[/i]??? | |
Re: There is freeware Qt for Windows now (from April 2009). There are some other freeware GUI libs for Windows - as usually, they are portable too. | |
Re: More precisely: [i]if the program attempts to modify an array corresponding to a string literal, the behavior is undefined[/i]. | |
Re: Try to understand the standard compilation process logic. Simplified translation process description: 1. Every .cpp file is processed separately (as if no other cpp files) 2. Preprocessor stage: process all # directives. Every active (see AD's post, #ifdef/#ifndef directives) #include directive in .cpp file is replaced by referred .h (or … | |
Re: [QUOTE=DinMan;881993]Hi! I would like to print a text file having some records onto the screen while running my program. Can sumone suggest me the easiest way to do it. I know I have to open the file using fopen() then what...[/QUOTE] Can you put more specific question? How to... - … | |
Re: Place your struct type definition in .h file: [code=cplusplus] struct Points { int xCoordinate; int yCoordinate; int zCoordinate; }; ... global functions prototypes [/code] Include this .h file in all modules (.cpp files) where Points type needed (in the main file too). Change array point declaration to [code=cplusplus] // main … | |
Re: Step by step instruction: 1. Start Visual Studio 2. Select Help | Index 3. Type LNK2001 in Look For field 4. Click on LNK2001 list element 5. Read about LNK2001 error 6. Error correction: obvious after steps 1-5 About LNK1120: 7. Close Visual Studio 8. Do the same procedure as … | |
Re: Keep it simple: [code=cplusplus] for (int i = 12; i; i--) cout << i << " times 3 = " << 3*i << '\n'; [/code] ;) | |
Re: See: you have [b]fac > no[/b] for all [b]no[/b] values because fac = n!. Therefore [b]no/fac == 0[/b] (integer division) and com=com+j is the same as com += 0... 1. Use [b]double[/b] type for math calculations (not float). 2. Use floating-point division if you want to get floating-point result, for … | |
![]() | Re: 1. By the way, you must define non-trivial copy constructor and assignment operator for this class String (or declare them as private to prevent inevitable program crash if default copy constructor and/or assignment will be called). 2. If you want String to std::string conversion, define it, what's a problem? [code=cplusplus] … |
Re: What's a monstrous post! Have you ever seen this forum rules? [url]http://www.daniweb.com/forums/announcement8-2.html[/url] [url]http://www.daniweb.com/forums/announcement8-3.html[/url] [noparse][code=cplusplus] source [/code][/noparse] Have you ever tried to read this awkward jumble of a third-party code? | |
Re: Good programmers are capable to write more effective programs practically in any programming languages than bad programmers can do it in machine codes ;) | |
Re: It's so easy: [code=cplusplus] typedef std::map<const char*,int,cmp_str> Map; void cleanup(Map& m) { for (Map::iterator i = m.begin(); i != m.end(); i++) free(const_cast<char*>(i->first)); m.clear(); } [/code] Be careful: this map must have keys allocated by C-functions strdup or malloc. | |
Re: I have created dummy text file like OP source (~572 Mb, 40000000 lines) then converted it to binary form with VC++ 2008 for ~3.5 minutes without special buffer control. That's OK, no problems. 1. Open both files in binary mode. 2. Inspect source file with hex editor. Probably it's corrupted. … | |
Re: Keep it simple: [code] fileName[0] = '\0'; // or even *fileName = 0; // to test: if (*fileName) { // non-empty [/code] ;) | |
Re: It's legal to [b]compare[/b] any pointer value with null pointer or any others pointer values of the same type. Better post your code fragment with segmentation fault. It's annoying to download the whole source, didn't you understand it? | |
Re: OP solution: [code=cplusplus] inline // interval [0..1) double drand() { return ::rand()/(RAND_MAX+1.0); } inline int randincr(int& counter, double p) { return drand() < p? ++counter: counter; } [/code] | |
Re: Probably the best method to build name list dictionary is: 1. Define std::map<std::string,unsigned> (dictionary name-counter) 2. Read names and insert them into the map (increment name counter if the name is in the map) 3. Traverse map with iterator: you will get an ordered ([i]automatically[/i];))name list with counters. If the … | |
Re: Keep it simple and effective: [code=cplusplus] const std::string& DayOfWeek(int dow) { static const std::string day[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "???" }; return day[dow < 0 || 6 < dow? 7: dow]; } [/code] | |
Re: You didn't include <string> header in main.cpp (for std::getline declaration). Change "iostream" and "fstream" to <iostream> and <fstream> (standard headers). You declare al variable in the if alternative block. Of course, this local variable is out of scope outside this block. Declare al at the main function body level - … | |
Re: Try Google: [i]C++ Java comparison[/i] Are you sure that it's a question for a half-page forum answer? | |
Re: May be you still remember (from a school math course) that no fractions which are equal to pi number. Other post correction: double type provide ~16 decimal digits precision (53 bits of mantissa). | |
Re: I was trying to understand what's [i]the ASCII value of a string of text[/i] (about 10 seconds or even more)... Alas... Can you explain what is it? Now I see why you [i]cannot seem to figure out how to convert the text into an ASCII value[/i]. However if you want … | |
Re: If you want to obtain hash index in a table of size B, don't forget: 1. Make [b]unsigned[/b] int calculations ([icode]x[i]-a[/icode] is signed value). 2. Result is sum % B. 3. As usually, no need to avoid integer overflow. May be better don't invent a square wheel? Are you familiar … | |
Re: That's a well-known identity: [code] A and B <=> not (not A or not B) [/code] As far as I know there are [i]not[/i] and [i]or[/i] operators in all versions of regular expressions... Remark on post#2: string::find returns unsigned value. It's a bad practice to assign it to int variables … | |
Re: May be it helps: [url]http://www.ucancode.net/Free-VC-Draw-Print-gdi-example-tutorial/Free-VC-Draw-Print-gdi-example-tutorial.htm[/url] ? | |
Re: > Hi all, > I am using Visual Studio 2005, and developing some application. Currently i am facing one problem. I have written a class and declared some member variables in the class. In the constructor i am initializing the member variables to 0(member variable is int). But when i … | |
Re: You (and me ;)) can't define member constructor parameters in the member declaration. Right solution: [code=cplusplus] class B { vector <A> a; int y; public: B():a(10) {} }; [/code] Apropos, erase semicolons after inline constructor definitions. >any idea... Read the language specifications more carefully ;) | |
Re: Please, post your code with code tag: [noparse][code=cplusplus] source [/code][/noparse] Read this forum announcement: [url]http://www.daniweb.com/forums/announcement8-3.html[/url] | |
Re: 1. You may get 26-th character of readLine as [icode]readLine[26][/icode] - why [icode]sscanf(readLine+26...)[/icode]? 2. Check input line length: may be no 26-th character in the line... 3. Why 'b' in +26 position corresponds to branch instruction? May be it's 'b' in the comment line... 4. Why +30 position corresponds to … | |
Re: Other code defects: 1. Right copy constructor signature is: [code] NumberList::NumberList(const NumberList&); [/code] 2. What happens if you want to initialize new list with empty list? The right answer: memory access failure occured. No obj.head == 0 test in copy constructor. 3. You must define overloaded operator=() or make it … | |
Re: What's a problem? [code=cplusplus] for (i = 0; len <= 0 && str[i] || str[i] && i < len; i++) { cio_putch(str[i]); } while (i++ < len) cio_putch(' '); [/code] | |
Re: abhishekp is right, but not class only and not global only: [code=cplusplus] int main() {} // do nothing!!! static struct __ { __() { cout << "Hello..."; } ~__() { cout << "Bye!\n"; } } _; [/code] | |
Re: tux4life, don't torment the unhappy C++ programmer, tell him/her about [icode]while(f>>i)[/icode] construct ;) | |
Re: >By the way: where do you close that file ? File stream destructor closes that file. That's OK. | |
Re: Sorry, what did you want to achieve with this senseless subexpression: [icode](op!='e')^(op==256)[/icode]? | |
Re: [QUOTE=William Hemsworth;877116]How unfair! I bought that book once, I never knew it was on msdn. :P[/QUOTE] Don't worry, buy yet another book! ;) | |
Re: Well, and where is the conversion formula? Now you have a very profitable business (fixed 13.20 pesos for 10$, 100$ etc). Other code defects: 1. The second is_number parameter defines a number of chars to be checked. However the 1st argument is C string and it can be shorter than … | |
Re: [icode]cout << r[0] << r[1][/icode] or [icode]cout << r.substr(0,2)[/icode] ;) | |
Re: It seems you don't understand my post in the recent thread where [i]Narue kindly gave you the answer[/i]: [url]http://www.daniweb.com/forums/thread194034.html[/url] There was your current problem solution in the code snippet. Probably you have a good chance to post your problem in loop forever manner ;) | |
Re: About that X extraction: Find "var sessionId = " then extract RandomKey. The last operation depends on the RandomKey terninator (or the next field delimiter). For example, if RandomKey field terninator is a blank char ' ' it looks like: [code=cplusplus] const size_t none = std::string::npos; std::string key, varid("var sessionID … | |
Re: 1. here's this forum announcement: [url]http://www.daniweb.com/forums/announcement8-3.html[/url] [noparse][code=cplusplus] source [/code][/noparse] 2. See an example of these cmds parsing: [code=cplusplus] // don't forget to include <sstream> typedef istringstream::pos_type Pos; // cmd arg parsing sample only: void cmdGet() { string line, cmd, arg; bool intarg = false; int iarg; cout << "Type instruction: … | |
Re: Of course, you have linker error because nobody (except you) knows such library function as [i]concat[/i] (probably you want strcat). The second attempt failed because fgets function puts the last '\n' character in the buffer (read library function specifications more carefully): [code] Input buffer after successful fgets: <line contents><'\n'><'\0'> [/code] … | |
Re: Avoid [icode]while (file.eof()) {...}[/icode] loop condition, it's a wrong pattern. Check file.eof() AFTER an input operation only. [code=cplusplus] ifstream file(filename); int n = 0; string line; while (getline(f,line)) { // Now you have a line! n++; } [/code] The simplest way to test C++ stream state: [code=cplusplus] if (!file) { … | |
Re: >what is array of void and why am I getting it in the following program? >I cannot figure out what this array of void is. Don't worry: nobody knows what's an array of void because no such animal in C and C++ languages ;) | |
Re: 1. Wrong reallocation in CStack::push. You must assign new memory block pointer value to the bottom_ pointer (see realloc specification carefully). Now you have memory corruption after realloc call. However it's wrong method to reallocate memory obtained by operator new with C library function realloc. Avoid using malloc, calloc and … | |
Re: >I wrote this code, but it didn't change anything You can't [b]compile[/b] this code, that's why it didn't change anything: the [b]else[/b] alternative has no correspondent if! Didn't you see it? What did you want to achieve with so strange [icode]a[i] == 8 || a[i] == 9[/icode] condition? It's a … |
The End.