1,296 Posted Topics
Re: [quote]Avoid listening to programming advice that says you absolutely must or must not do something.[/quote] Good metaprogramming advice ;) [i]Never forget to declare C++ variables before...[/i] To ignore or not to ignore? ;) Is it an advice or a requirement? Where is the border?... | |
Re: It's not only the most slow algorithm (the original one) but it's a wrong algorithm. You have got not a sum of digits but a sum of char codes of digits. It's the other story that char code of '0' is even numbert in ASCII table; the C language does … | |
Re: [icode]deque<string>(). swap(text);[/icode] It's a very radical method to deallocate memory occupied by STL container. The point is that it's unclear (in the current C++ Standard) if the clear(;)) method makes capacity == 0 (i.e. really deallocate memory, not only set the size of container to zero). This expression statement creates … | |
Re: Cascades of monstrous data moving... have you ever heard about operator= in C++? [code=cplusplus] clients[i] = clients[i+1]; [/code] instead of awful (quote): [code=cplusplus] clients[i].name=clients[i+1].name; clients[i].table_number=clients[i+1].table_number; clients[i].type=clients[i+1].type; clients[i].bill=clients[i+1].bill; clients[i].order.soup=clients[i+1].order.soup; clients[i].order.salad=clients[i+1].order.salad; clients[i].order.beefsteak=clients[i+1].order.beefsteak; clients[i].order.pizza=clients[i+1].order.pizza; clients[i].order.pancake=clients[i+1].order.pancake; clients[i].order.cake=clients[i+1].order.cake; clients[i].order.soda=clients[i+1].order.soda; clients[i].order.whisky=clients[i+1].order.whisky; [/code] That famous [icode]system("pause")[/icode] after prompt "Try again" ??? It seems no once input result … | |
Re: [code=c] int cheat_in_place(const char* sheet, char looser, char winner) { int n = 0; long fsz; char* buf, *p; FILE* f; if (!sheet) return 0; f = fopen(sheet,"r+b"); if (!f) return 0; if (fseek(f,0L,SEEK_END) == 0 && (fsz = ftell(f)) > 0) rewind(f); else { fclose(f); return 0; } buf … | |
Re: [QUOTE=jaguar_s;847071]I need to read data from a data register n times and calculate the average of that and write it into another data register.... I dont know how to do this at all...[/QUOTE] You need an assembler level programming. Are you familiar with assembler language(s)? | |
Re: Of course, you need try-catch construct to intercept exceptions. Nobody can call what() member function without alive (raised) exception object: what() of ... what? What's a problem? [code=c++] int main() { int rc = 0; // prologue try { // processing } catch (runtime_error& ups) { cerr << ups.what() << … | |
Re: 1. Niklaus Wirth. Algorithms + Data Structures = Programs. Prentice Hall etc... 2. The char type values range provides much (much) more suitable data structure: a simplest 1D array. Be careful: char may be signed or unsigned (it's an implementation-defined issue)... ;) | |
Re: [url]http://www.cs.utsa.edu/~dj/ut/utsa/cs3343/lecture7.html[/url] Yes, common priority queue implementations are based on heap data structure founded on a linear (as usually, in array) representation of a tree... ;) | |
Re: [QUOTE=MrSpigot;846742]Well I would appreciate you backing up a statement like that! There are 2 threads here. One reads and writes (ie an addition), the other just reads. Two threads can indeed access the same memory quite happily (ok there might be some exceptions for custom embedded systems, but we're talking … | |
Re: [QUOTE=Niner710;846219]Is there anything that is free that I can use? I saw Install shield is pretty expensive.[/QUOTE] In most of simple cases you can pack all distributive files in SFX archive (a single compact exe). There are lots of freeware archivers which can do that (7-Zip, for example). | |
Re: You declare yet another local i in if alternative of CarregaPNM::ReturnPNM_header. This declaration hides variable i - loop counter. It's a very strange and most probably erroneous declaration. It seems the program logic is corrupped... Apropos, avoid illusions: this evil fstream knows nothing about your classes and no such beast … | |
Re: Other defects: 1. No input result checking. For example, if an user types not a number(s) the program behaviour is undefined. 2. Incomprehensible and misleading prompts. | |
Re: [QUOTE=YaelGD;845278]Hello again! I just wanted you to know that I solved it, I forgot a tiny detail that makes all the difference: I have to sort numbers from 0 to 9. That means that I can sum the times a number appears and print it from the lowest to the … | |
Re: You declare the first arrAscendingOrder and showArrPtr paremeter as an array of [b]pointers[/b] to double ( Why?! ). However the only array (accessed via score pointer) in your program is an ordinar array of doubles. You are trying to pass it in these functions. See your showArray correct parameter declaration … | |
Re: If possible (this case) better sort an array of pointers to words but not an array of words. In actual fact it's unclear what to do with multiple occurences of the same word in OP assignment. An optimal algorithm (and data structure) depends on this specification. For example, if you … | |
Re: Of course, you can't initialize array of singleIMEI elements to "null" because no such value as '\0' or 0 of singleIMEI type. However an array of class objects initializes by default class constructor in C++ (did you remember that a struct is a class with all public members in C++ … | |
Re: [QUOTE=Laik;845069]How to make a new scripting language in C++ ?...I need: parser,scanner,grammar,included functions,syntax.Where I can start?. I think I use JavaScript/PHP syntax.[/QUOTE] Just before you start to design grammars (the language grammar is the same thing as the language syntax ;)), scanners, parsers, libraries etc - it's a good idea … | |
Re: Try GetVersionEx Windows API function. See MSDN article(s): [url]http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx[/url] | |
Re: In most of C and C++ implementations the time() returns the elapsed time in seconds from the Unix epoch. However both C and C++ standards do not specify time_t type granularity and the day of epoch. Therefore all programs based on "time_t in seconds and time() returns seconds from ...1970" … | |
Re: [QUOTE=guest7;844738]Hi, How can i delete the file in the middle of the program in C++ [/QUOTE] Probably in the same manner as in the program head or in the program tail: close all streams associated with the file then use [icode]remove(filepath)[/icode] library function declared in <cstdio>. | |
Re: Yet another tip: use std::map<std::string,int> to build word dictionary and maintain word counters. | |
Re: No need to truncate filename: zero byte logically terminates C-style text strings. Better think about another (true) problem: what happens if filename contents length is greater than 40 - 1 (zero byte) - 4 (extension length) == 35... Tip: you will get the program crash... | |
Re: Well, split the problem: subproblem 1. find substring subproblem 2. if found, make a room (move the rest forward or back) subproblem 3. copy new string contents to the room Better forget the snippet presented above: it's a very very bad replace implementation (the worst I've ever seen ;) - … | |
Re: 1. All matrices are 2D arrays by definition ;) 2. As usually, matrix classes provide matrix oriented operations (transpose, invert, matrix arithmetics etc. Are you sure that you need all these features for [i]simple game navigation[/i] (can't imagine what's a beast)? 3. May be better try to present some of … | |
Re: Please, read this forum rules: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] | |
Re: That's because there are [icode]xd[0][/icode] and [icode]xd[1][/icode] only elements in the array [icode]int xd[2][/icode] ;)... | |
Re: The second case is not a declaration of Link<int> instance (object), that's why it was "[i]compiled fine[/i]". It's a prototype of a function (never called) without parameters returned Link<int> object. Most of C++ compilers can't process programs with separated template definition and implementation. Move Link template constructor from list.cpp to … | |
Re: The _beginthread first parameter is a pointer to an [b]ordinar[/b] function, not a pointer to member function. There are two absolutely different sorts of pointers in C++. See, for example: [url]http://www.goingware.com/tips/member-pointers.html[/url] | |
Re: 1. Use code tag correctly: [noparse][code=c] source [/code][/noparse] 2. Have you ever heard that all names must be declared before used in C? If not, take your textbook again. If yes, what's str (or str2) in strcat385 body? 3. What's an index of string2 element in [icode]string1[i] = strign2[];[/icode]? Can … ![]() | |
Re: [QUOTE=Clockowl;844279]You can easily test that, just put some messages in the destructor and some in the program itself to see its place right? ;)[/QUOTE] Yes, that's true. The C++ Standard requires that objects associated with std::cin, std::cout and std::cerr are destroyes after destruction of user-defined objects with static duration: [quote]Constructors … | |
Re: Are you sure that you select correct project properties? Probably, you are trying to write Win32 [b]console[/b] application as Win32 project (Windows GUI API based program)... | |
Re: 1. Operator priorities: `a<<2 + a` treated as `a << (2+a)`. 2. Undefined result; side effect of ++ operators and undefined order of argument list evaluation, cases `<2>+=pow(2,2), <3>+=pow(2,3)` and others are possible... 3. It's only the `union U` type (not a member) declaration in struct s definition body. | |
Re: As far as I know it happens after "compilation" of .h files. Insufficient info... | |
Re: Can you explain why you have invented so strange manner to die for your top secret application? ;)... | |
![]() | Re: >I notice that you need to pass the vector by reference to add and del. Not only in add and del but in read_in too: this function fills a copy of its argument (passed by value) so the caller never gets any contents. ![]() |
Re: That's your problem: [code=c++] void TextUtil::isnotpuct() const { //_word_list is the vector<string> type ... _word_list[i] = ""; ... [/code] const member function can't modify other members. WHY this function-predicate has so drastic side effect?! Yes, it's a ghost post... May be once morning this code will be compiled successfully... | |
Re: Yet another defects (obvious): 1. The comparelist function does not compare lists, it compare two integers (now). Moreover, the 3rd parameter of equal semantically defines "compare nodes" function! The natural 3rd parameter prototype is `int(*p_cmp_f)(const int*,const int*)` or even `int(*p_cmp_f)(const NODE*,const NODE*)`. 2. Extremely ineffective function equal implementation. For example, … | |
Re: Better post a code where *macro doesn't seem to work*. More accurate this substitution definition is #define stack_empty(x) (*(x) == 0) However it's a strange parameter type `stack**`. It has two indirections - why? If you have a modern (standard-compliant) compiler better use **inline** keyword... | |
Re: Some remarks to the previous post: 1. Alas, [icode]argv[0][/icode] IS NOT a path of exe module. The C standard (5.1.2.2.1 Program Startup): [quote]If the value of argc is greater than zero, the string pointed to by argv[0] represents the [i]program name[/i]; [icode]argv[0][0][/icode] shall be the null character if the program … | |
Re: [QUOTE=jencas;842260]Question: Did you ever try the forum search function? Answer: NO, NO, NO and NO Proof: [url]http://www.daniweb.com/code/snippet912.html[/url][/QUOTE] Ehh, this link refers to a very strange, ineffective and incorrect roman to arabic numerals converter. Moreover: it's impossible to compile this snippet w/o errors with a good compiler... Proof: try to convert … | |
Re: In other words, accessors/mutators and semaphores are absolutely different beasts. Accessors and mutators are member functions. Semaphores are objects with special sets of operations and values. In generally semaphores are rather types and accessors/mutators are essentially operations. So the question looks like [i]what's a difference between door-handles and padlocks?[/i] ;) | |
Re: [QUOTE=tux4life;842148]Yeah, it's true what niek_e said ... You could make use of a function like this one: [CODE=C++] int get_range(int a, int b) { int c; do { if(c > a && c < b) return c; else cout << "Please enter a number between " << a << " … | |
Re: That's why you don't check a result of an user input in [icode]cin >> numberofopponents[/icode]. If you try to input a letter instead of a number then cin stream goes to a failed state and does not change operator >> target. So you will get loop forever because the next … | |
Re: 1. Wrong assignment operator (default member by member assignment can't work with such objects - think why). 2. No correct copy constructor (default copy constructor can't copy such objects). That's why your program crashed. 3. Some other defects ;) [code=c++] StRiNg::StRiNg(const char* s) // const ! { if (s == … | |
Re: 1. Use code tag correctly: [noparse][code=cplusplus] source(s) [/code][/noparse] 2. You forgot to initialize listData in operator=() 3. You forgot to delete old list in operator=() 4. You forgot to check [icode]if (this != &anotherList)[/icode] in operator=() 5. Use listDate or topPtr to point to the list head, not both ... … ![]() | |
Re: Keep it simpler ;) [code=c++] bool getSSN(string& ssn) { while (cout << "Enter SSN as ddd-dd-dddd: ", cin >> ssn) { if (ssn.size() == 11 && ssn[3] == '-' && ssn[6] == '-') { int digits = 0; for (int i = 0; i < 11; ++i) if (isdigit(ssn[i])) digits++; … | |
Re: 1. You don't remove items from an array, you print all elements except removeItem. It's a solution of another problem. 2. Count removeItem occurences then print a proper message(s) if counter == 0 or counter == ARRAY_SIZE. Let removeAll returns this counter value or a new number of array elements … | |
Re: Did you say that [icode]double sqrt(double x);[/icode] is [i]a double that is also a function[/i]? It's a prototype of a function named sqrt returning double value! So you have a prototype (declaration) of a function named find_node with two parameters. It returns a pointer to (found) structure (probably, a node … | |
Re: 1. Please, use code tag correctly: [noparse][code=cplusplus] sources [/code][/noparse] 2. Is it a question?.. or presentation? ;) |
The End.