1,296 Posted Topics

Member Avatar for athar89

1. You forgot that strcat works with c-strings i.e. char arrays with null byte at the end of contents: [code=c++] void express::parse(){ int i=0,x=0; char ch; // it's a single char, not char array while(i<len) { if (ch >= '0' && ch <= '9') { char* a; float f; int …

Member Avatar for Murtan
0
185
Member Avatar for NewtoC++

Please, read your C++ book again (at least how to declare class variables and access its members). It seems all you know about C++ at the moment: // comments and operator << ;) Probably you can't understand the answer to your question now ([icode]age.("name") = age;[/icode] - it's cool! )...

Member Avatar for NewtoC++
0
18K
Member Avatar for oky20

>But I don't understand how to sort the information in alphabetic order. Do you know any sorting algorithm? If not, come here: [url]http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx[/url] >And also the information which is written in information.txt is not neat. ???

Member Avatar for oky20
0
107
Member Avatar for scrypter

The inner class does not have special access rights to outer class members, it's not a member of outer class (common misunderstanding of novices). The only effect is that inner class name scope is bounded by outer class. It's the same as ordinar (outside another class definition) class declaration in …

Member Avatar for ArkM
0
166
Member Avatar for mrnutty

It's not a class called, you call a member function for an object of another class. So if you can declare a variable of the class (as a member, for example) then you can call member functions of this variable class. Now let's remember: you must declare an entity before …

Member Avatar for ArkM
0
89
Member Avatar for Manutebecker

[QUOTE=Manutebecker;760540]I must say I always love a program where I can use #include<vector> vectors are like the peanut butter to my chocolate![/QUOTE] Well, start all your modules from [code=c++] #include <vector> using std::vector; [/code] Who knows what may happen below ;)...

Member Avatar for Manutebecker
0
129
Member Avatar for m24r

1. Please, USE code tag for your snippets properly: [code=c] your source texts [/code] 2. You don't understand operator sizeof functionality. See what happens in your (incorrect) memory allocation: glblclrtab= (char *)malloc(sizeof(3*tmp)); The malloc functions allocates `sizeof(3*tmp)` bytes. The C Standard: >The sizeof operator yields the size (in bytes) of …

Member Avatar for death_oclock
0
168
Member Avatar for Frederick2

Obviously, the presented output was printed by another (version of) program (no member names in this snippet printf). Of course, VC++ 6.0 is too old compiler but I have worked with it many years and never have troubles with printf... Try to replace printf to cout << and see what …

Member Avatar for ArkM
0
217
Member Avatar for boomtoom

Let's start from this forum announcement: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] I rather like this non-functional specification: [quote]please try to make it as simple as you can[/quote] Did you know the most valued principle of a good programming style and design: [b]Keep it simple, stupid[/b]? If so you have a good chance to become …

Member Avatar for cikara21
0
160
Member Avatar for arunciblesp00n

Alas, [b]long long int[/b] is not a standard type in C++ at the moment. Moreover, the C++ (and C) standard garantees that long number type is not less that ordinar type - that's all (for example, [icode]sizeof(long long int) >= sizeof(long int)[/icode], but not [icode]sizeof(long long) > sizeof(long)[/icode]). Therefore it …

Member Avatar for ArkM
0
5K
Member Avatar for skalber

1. You may assign any type object pointer to a void* pointer variable without explicit conversion - no need in reinterpret_cast: [code=c++] void* pvoid[3]; pvoid[0] = &mc1; // or what else [/code] 2. It's possible but what for? All three variables mc1, mc2, mc3 have absolutely different types. Can you …

Member Avatar for ArkM
0
139
Member Avatar for suljo2

1. There are lots of fixed decimal/currency class libraries for C and C++: search Google. 2. What's a problem? Calculate all values in cents (use double type, don't forget floor and ceil library functions, Banker rounding method etc). Some year ago I have wrote ~100000 LOC of financial codes with …

Member Avatar for ArkM
0
144
Member Avatar for gumber

>first i copy an object byte by byte to a memory location It's one of the most dangerous operations (in general case illegal and erroneous), as usually symptom of a very bad code design. The only valid conversion void* to type* value is: the void* pointer value was obtained previously …

Member Avatar for gumber
0
167
Member Avatar for ecentric

Look at the sentence: [b]Well,find me[/b]. Are you sure that whitespaces only are valid word separators?

Member Avatar for ArkM
0
2K
Member Avatar for shaikh_mshariq

[QUOTE=shaikh_mshariq;762983]I need to write a small application which can be used to store html from any web server. I have written some code that is able to fetch HTML page along with header. I need to know is there any way to distinguish these headers from actual html content. Can …

Member Avatar for Salem
0
1K
Member Avatar for dewyatt

I don't understand why you consider these three methods equally matched. The 1st method only builds the desired multimap. I think the std::multimap native interface is not suitable for most of applications (too cumbersome and unclear), so you need your own problem-oriented multimap wrapper class. You may initialize static multimap …

Member Avatar for dewyatt
0
320
Member Avatar for crioto

[QUOTE=crioto;762386]For example, i have char variable = "This is a simple text"; and i need to put word "Very" between "a" and "simple" How to do it using standart C library?[/QUOTE] Use strstr library function to search "Very" in the string. If it's found make a room at this point …

Member Avatar for ajay.krish123
0
87
Member Avatar for 1bennyd

>I am trying to solve an easy problem (no doubt) - reading data from a tab delimited file and inserting it into a 2D array. Well, try to solve THIS problem: you have 4x5 integers in the text file and you need to read them into 2D INTEGER array, not …

Member Avatar for 1bennyd
1
255
Member Avatar for lehe

Think: a console program does not know what device receives stdout/cout output! Suppose you have prog.exe. See what happens when prog.exe started: 1. >prog -- ok, printf prints in console window 2. >prog >output.txt -- printf writes in file output.txt 3. >prog >nul -- printf "prints" nowhere (nul device - …

Member Avatar for ajay.krish123
0
123
Member Avatar for mesnomer

Despite of this barbaric by value queue parameter and absolutely unnecessary copying to the local temp variable, it's a correct code. It works if the queue was initialized properly. Present outputQueue call context...

Member Avatar for ArkM
0
84
Member Avatar for Darkmystery
Member Avatar for Darkmystery
0
156
Member Avatar for jimbob90

[url]http://www.exforsys.com/tutorials/c-plus-plus/how-to-access-class-members.html[/url]

Member Avatar for ArkM
0
289
Member Avatar for Lukezzz

Didn't you see that you show TWO open file dialog windows? You close the 1st dialog and immediately show the 2nd one in if expression... What for the 1st line of your snippet? Please, next time use code tag properly: [noparse][code=c++] text [/code][/noparse]

Member Avatar for Lukezzz
0
128
Member Avatar for Ragupathiyuva

[QUOTE=Ragupathiyuva;759961] Can anybody explain about int main(int argc,char* argv[]) [/QUOTE] Google search "main C argc argv tutorial"... Instant replay: lots of links RIGHT NOW... For example: [url]http://www.phon.ucl.ac.uk/courses/spsci/abc/lesson11.htm[/url] [url]http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html[/url] [url]http://www.dgp.toronto.edu/~ajr/209/notes/argv.html[/url] and so on...

Member Avatar for Narue
0
387
Member Avatar for Manutebecker

[code=c++] union BinCard{ uint64 Hand; // uint64 is an unsigned 64 bit int (use a typedef) SuitGrp SG;}; [/code] How about this solution portability? There are lots of compilers without 64-bit integer types ;)...

Member Avatar for ArkM
0
265
Member Avatar for declan12

It's unclear where global array definitions were placed. Probably, these [icode]#ifndef...char[][]={}...#endif[/icode] chain was placed twice. Place extern declarations only fragment in separated .h file, include it in .c modules where external arrays access needed. External arrays definitions (declarations with initialization) must be placed in one and only one source file …

Member Avatar for Salem
0
769
Member Avatar for phuc_tran

Have a look at the C++ creator's pages: [url]http://www.research.att.com/~bs/C++0xFAQ.html[/url]

Member Avatar for phuc_tran
0
51
Member Avatar for Stonehambey

Alas, it's wrong solution because [icode]sizeof(T[])/sizeof(T)[/icode] does not bear a relation to an array size: it's the same as [icode]sizeof(T*)/sizeof(T)[/icode]. Remember: it's impossible to get an array size from [icode]type name[][/icode] declaration. Look at: [code=c++] template <typename T> class Sequence { public: Sequence() {} Sequence(const T a[], size_t n): terms(a,a+n) …

Member Avatar for Stonehambey
0
144
Member Avatar for mini programmer

Please, don't worry about that sacramental [b]third call[/b]! If strtok can't find third slash it returns the pointer to the start of year field (or what else after the second slash), but [b]the next[/b] call returns NULL. In other words, strtok returns NULL only when all c-string was scanned. For …

Member Avatar for mini programmer
0
151
Member Avatar for sweeya

Define your own manipulators, make a code simpler: [url]http://www.java2s.com/Tutorial/Cpp/0100__Development/Createanoutputmanipulator.htm[/url] ;)

Member Avatar for grumpier
0
193
Member Avatar for sweeya

Visual C++ 9.0 compiler resolves this situation. Obvious workaround with your compiler: define explicitly default RMStore constructor (an all others): [code=c++] class RMStore { public: // Place public part at the beginning RMStore():status(false){} // You forgot initialize status member explicit RMStore(const char* pcmd): command(p?p:""),status(false) {} explicit RMStore(const std::string& cmd): command(cmd),status(false) …

Member Avatar for ArkM
0
126
Member Avatar for Manutebecker

Well, class System HAS a vector of Schools. In other words, every System object contains a set of Schools. But class School IS a kind of System (by inheritance). So every School has a set of Schools?!.. Hmm...

Member Avatar for Manutebecker
0
105
Member Avatar for mrnutty

Well, it's too narrow and a little obscure code ;) I agree with previous posts. >can it be more efficent? What's your effectiveness criteria? [code=c++] bool Palindrome(const char* p) { if (!p) return false; if (!*p)return true; const char* pend = p; while (pend[1]) ++pend; while (p < pend && …

Member Avatar for grumpier
0
99
Member Avatar for serkan sendur

The C++ Standard (16.2): [quote]2 A preprocessing directive of the form # include <h-char-sequence> new-line searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. …

Member Avatar for Narue
0
109
Member Avatar for karang

[QUOTE=karang;759744]if I have a variable called text of type char* then What should I write in VC++ so that it assigns emdash value in the variable text[/QUOTE] 1. The emdash character has value '\x97' in most of Windows single-byte code pages (it's equal to -105 if char type is signed …

Member Avatar for ArkM
0
378
Member Avatar for Manutebecker

[QUOTE=Manutebecker;750641]I've been reading up on templates and they just seem like so much hastle for so little reward. I can't find anyway to effectively use it over vectors. I am just having a lot of trouble learning them because the concept seems so weird.[/QUOTE] Google "C++ templates tutorial" Lots of …

Member Avatar for ~s.o.s~
0
142
Member Avatar for lulusweety

[QUOTE=lulusweety;759119]Can you tell me which compiler(version) is suitable for doing exception handling?[/QUOTE] Have you ever read Ancient Dragon's post? Use Code::Blocks IDE with MinGW compiler (the same as frozen Dev-C++ IDE used): [url]http://www.codeblocks.org/[/url]

Member Avatar for Freaky_Chris
0
166
Member Avatar for rkumaram

[QUOTE=rkumaram;759124]... when we called constructor , it allocate memory for the object . right . [/QUOTE] A constructor does not allocate memory for the object. It does not know how to do that. Think about: [code=c++] class C { public: C(); C operator+(const C&); } ... C c; // static …

Member Avatar for rkumaram
0
170
Member Avatar for d1s_0n3_guy

1. Use code tags: [noparse][code=c++] your code [/code][/noparse] 2. You don't understand a role of "stdafx.h" header in VC++. Place all system header includes in stdafx.h, not in your cpp modules: [code=c++] stdafx.h: ... #include <iostream> #include <fstream> #include <string> // TODO: reference additional headers your program requires here yourcppfile.cpp: …

Member Avatar for ArkM
0
119
Member Avatar for cusado

It works but too slowly (over two billions unnecessary loops) ;) Break the loop when you know that it's not a prime (and try to optimize code because it's a brutal force slow algorithm): [code=c++] ... // positive root_value only... double c = 2.0; bool prime = true; root_value = …

Member Avatar for ArkM
0
120
Member Avatar for CoolAtt

It's a good time to remember header files. Place the structure definition in .h file then include it in both main.c and file2.c. Now you have common structure (and other types) definition source. A compiler knows nothing about main.c contents when processes file2.c.

Member Avatar for ArkM
0
135
Member Avatar for brixton

[QUOTE=Luckychap;758462]You cannot declare array with a variable size.[/QUOTE]It's true but [icode]new float[arrayLength][/icode] construct is not an array declaration: operator new creates anonymous array object, a new argument (number of elements) is an arbitrary arithmetical type expression.

Member Avatar for ArkM
0
75
Member Avatar for kevintse

[QUOTE=Narue;757781]...though it's usually a better idea to design your class so as to not need a default value.[/QUOTE] It's not so easily to design an intrusive container class for elements without default constructor (no underlying arrays, for example).

Member Avatar for kevintse
0
139
Member Avatar for callprem26

1. No loops, no (run-time ;) ) recursion: [code=c++] template <int n> struct Hello: public Hello<n-1> { Hello() { std::cout << "Hello, world!\n"; } }; template <> struct Hello<0> {}; int main() { Hello<100> woodpecker; return 0; } [/code]

Member Avatar for Narue
0
179
Member Avatar for 30Caliber

1. You have made a very bad style functional decomposition. Why an array is global? Define all processing functions with processed array and array size parameters. Never burden your functions with redundant external dependencies. You CreateArray function does not create an array (it was created by a declaration statement), it …

Member Avatar for 30Caliber
1
2K
Member Avatar for Manutebecker

[QUOTE=Manutebecker;757431]After reading up on them in terms of class hierarchy, they seem to just be almost like comments, to remind you that all classes use this sort of function[/QUOTE] ???!!! It's a false statement (or I misunderstand the post).

Member Avatar for ddanbe
0
261
Member Avatar for clutchkiller

Look at the excellent tutorial by Julienne Walker: [url]http://eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx[/url]

Member Avatar for ArkM
0
84
Member Avatar for Lukezzz
Member Avatar for ArkM
0
92
Member Avatar for hamadak

A has-a relationship between classes is not an inheritance (see, for example, [url]http://en.wikipedia.org/wiki/Has-a[/url]). What's a problem? can you describe it more specifically? It's not a question: "I don't know how to write constructors and destructors".

Member Avatar for hamadak
0
94
Member Avatar for Ameerah

1. Why the last statement of [icode]Student Student::operator+[/icode] is [icode]return false[/icode]? Are you sure that one Student added to another Student is a Student again? ;) 2. Look at braces in this operator body. Why you wrote two braces one after another in if statement? 3. Don't print messages in …

Member Avatar for Salem
0
124

The End.