1,296 Posted Topics

Member Avatar for kelechi96

[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?...

Member Avatar for kelechi96
0
170
Member Avatar for FREEZX

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 …

Member Avatar for tux4life
0
1K
Member Avatar for guest7

[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 …

Member Avatar for nucleon
0
240
Member Avatar for scarebyte

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 …

Member Avatar for scarebyte
0
769
Member Avatar for Francis87

[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 …

Member Avatar for ArkM
0
313
Member Avatar for jaguar_s

[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)?

Member Avatar for ArkM
0
110
Member Avatar for Clockowl

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() << …

Member Avatar for Clockowl
0
107
Member Avatar for r1ian2

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)... ;)

Member Avatar for ArkM
0
94
Member Avatar for TuX4020

[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... ;)

Member Avatar for jrw0267
0
138
Member Avatar for f.ben.isaac

[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 …

Member Avatar for Clockowl
0
151
Member Avatar for Niner710

[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).

Member Avatar for ArkM
0
125
Member Avatar for Icebone1000

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 …

Member Avatar for Icebone1000
0
277
Member Avatar for Akis2000

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.

Member Avatar for Akis2000
0
112
Member Avatar for YaelGD

[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 …

Member Avatar for Narue
0
116
Member Avatar for pt_solar

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 …

Member Avatar for pt_solar
0
553
Member Avatar for harshaldhote

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 …

Member Avatar for jephthah
0
385
Member Avatar for vishy_85

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++ …

Member Avatar for Ancient Dragon
0
1K
Member Avatar for Laik

[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 …

Member Avatar for siddhant3s
0
259
Member Avatar for nitinmukesh

Try GetVersionEx Windows API function. See MSDN article(s): [url]http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx[/url]

Member Avatar for nitinmukesh
0
294
Member Avatar for aiosarem

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" …

Member Avatar for ArkM
0
4K
Member Avatar for guest7

[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>.

Member Avatar for MosaicFuneral
0
171
Member Avatar for sautap4u

Yet another tip: use std::map<std::string,int> to build word dictionary and maintain word counters.

Member Avatar for nucleon
0
112
Member Avatar for guest7

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...

Member Avatar for ArkM
0
95
Member Avatar for vijaysoft1

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 ;) - …

Member Avatar for ArkM
0
131
Member Avatar for sweetApple

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 …

Member Avatar for ArkM
0
115
Member Avatar for namour84

Please, read this forum rules: [url]http://www.daniweb.com/forums/announcement8-2.html[/url]

Member Avatar for ArkM
0
104
Member Avatar for FREEZX

That's because there are [icode]xd[0][/icode] and [icode]xd[1][/icode] only elements in the array [icode]int xd[2][/icode] ;)...

Member Avatar for FREEZX
0
85
Member Avatar for jesseb07

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 …

Member Avatar for jesseb07
0
6K
Member Avatar for nschessnerd

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]

Member Avatar for Ancient Dragon
0
136
Member Avatar for uscuba2_2001

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 …

Member Avatar for iamthwee
0
138
Member Avatar for sciwizeh

[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 …

Member Avatar for ArkM
0
3K
Member Avatar for Matzbyy

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)...

Member Avatar for Ancient Dragon
0
98
Member Avatar for want_to_code

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.

Member Avatar for Aia
0
174
Member Avatar for mathueie
Member Avatar for tux4life
0
5K
Member Avatar for Akis2000

Can you explain why you have invented so strange manner to die for your top secret application? ;)...

Member Avatar for Akis2000
-1
797
Member Avatar for xcr

>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.

Member Avatar for xcr
0
145
Member Avatar for shasha821110

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...

Member Avatar for ArkM
0
78
Member Avatar for Dewey1040

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, …

Member Avatar for Dewey1040
0
86
Member Avatar for Zolookas

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...

Member Avatar for Zolookas
0
107
Member Avatar for tonyaim83

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 …

Member Avatar for adam1122
0
6K
Member Avatar for vijaysoft1

[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 …

Member Avatar for siddhant3s
0
100
Member Avatar for Nemoticchigga

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] ;)

Member Avatar for ArkM
0
135
Member Avatar for badboizEnt

[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 << " …

Member Avatar for badboizEnt
0
145
Member Avatar for shadowmann2330

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 …

Member Avatar for ArkM
0
142
Member Avatar for u8sand

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 == …

Member Avatar for tux4life
0
124
Member Avatar for sfrider0

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 ... …

Member Avatar for jencas
0
121
Member Avatar for CPPRULZ

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++; …

Member Avatar for ArkM
0
116
Member Avatar for YingKang

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 …

Member Avatar for YingKang
0
194
Member Avatar for MaestroRage

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 …

Member Avatar for ArkM
0
95
Member Avatar for redhotspike

1. Please, use code tag correctly: [noparse][code=cplusplus] sources [/code][/noparse] 2. Is it a question?.. or presentation? ;)

Member Avatar for redhotspike
0
239

The End.