1,296 Posted Topics

Member Avatar for chaines51

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 …

Member Avatar for ArkM
0
171
Member Avatar for seemant_sun

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

Member Avatar for seemant_sun
0
484
Member Avatar for animefun2

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 …

Member Avatar for seemant_sun
0
196
Member Avatar for gnobber

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

Member Avatar for DonB
0
327
Member Avatar for atman

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

Member Avatar for siddhant3s
0
123
Member Avatar for Usura

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

Member Avatar for William Hemsworth
0
98
Member Avatar for seemant_sun
Member Avatar for AbsoluteCPP

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

Member Avatar for WaltP
0
101
Member Avatar for seemant_sun

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

Member Avatar for Ancient Dragon
0
137
Member Avatar for JackDurden

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 …

Member Avatar for VernonDozier
0
255
Member Avatar for abhishekmadaan

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

Member Avatar for ArkM
0
98
Member Avatar for bjanbkboi

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

Member Avatar for ArkM
1
108
Member Avatar for clisen

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 …

Member Avatar for clisen
0
185
Member Avatar for rabbitwat2

Why strncat? Make a single (expected) string by a single snprintf call. What's a problem?

Member Avatar for rabbitwat2
0
157
Member Avatar for gretty

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 …

Member Avatar for yun
0
173
Member Avatar for guest7

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

Member Avatar for guest7
0
108
Member Avatar for dumrat

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 …

Member Avatar for ArkM
0
129
Member Avatar for timb89

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

Member Avatar for ArkM
0
108
Member Avatar for nustian

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 …

Member Avatar for ArkM
0
148
Member Avatar for deostroll

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

Member Avatar for ArkM
0
107
Member Avatar for Aseem_Pandey
Member Avatar for NathanOliver

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

Member Avatar for NathanOliver
0
152
Member Avatar for vanalex

Thanks God, -> and . have the same precedence and associativity. The OP example with a pointer parameter works fine in VC++ 2008. Diagnosis: insufficient info ;)

Member Avatar for iJimJones
0
130
Member Avatar for horiya

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 …

Member Avatar for tux4life
0
133
Member Avatar for clisen

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]

Member Avatar for clisen
0
130
Member Avatar for andonyan

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 …

Member Avatar for Sky Diploma
0
323
Member Avatar for Aseem_Pandey

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

Member Avatar for Aseem_Pandey
0
282
Member Avatar for KickAss2k1

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

Member Avatar for ArkM
0
254
Member Avatar for ogwiz

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 …

Member Avatar for ArkM
2
106
Member Avatar for seemant_sun

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.

Member Avatar for ArkM
0
76
Member Avatar for Pavan_

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 …

Member Avatar for ArkM
0
148
Member Avatar for mbartos

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]

Member Avatar for ArkM
0
322
Member Avatar for hypernova

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

Member Avatar for s_sridhar
0
137
Member Avatar for gretty
Member Avatar for gretty

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 …

Member Avatar for siddhant3s
0
265
Member Avatar for osmano807

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 …

Member Avatar for ArkM
0
121
Member Avatar for lukethedrifter

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]

Member Avatar for Ancient Dragon
0
226
Member Avatar for catchmrbharath
Member Avatar for red999

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 …

Member Avatar for kvprajapati
0
2K
Member Avatar for fadia

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

Member Avatar for ArkM
0
137
Member Avatar for nagu89

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 …

Member Avatar for ArkM
0
121
Member Avatar for catchmrbharath

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 …

Member Avatar for ArkM
0
138
Member Avatar for san gabriel

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

Member Avatar for mirfan00
0
446
Member Avatar for hiscasio

Better try to read this forum rules before 6th of June: [url]http://www.daniweb.com/forums/announcement8-2.html[/url]

Member Avatar for hawash
0
148
Member Avatar for lexusdominus
Member Avatar for Chumpcash

Line #172 and below: statements outside function body... Where is this function header?

Member Avatar for Yiuca
0
175
Member Avatar for clutchkiller

[code=cplusplus] char* arr = new char[...]; f.read(reinterpret_cast<char*>(arr), ... [/code] Why reinterpret_cast?..

Member Avatar for ArkM
0
146
Member Avatar for meb111

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

Member Avatar for ArkM
1
99
Member Avatar for defender_

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 …

Member Avatar for ArkM
0
108
Member Avatar for Ray Gray

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

Member Avatar for ArkM
1
104

The End.