353 Posted Topics

Member Avatar for tennis

@tennis > 1. an int and a class with only an int member, are they of the same size? Maybe. The size of a class will be the total bytes of the data members and any padding. It is the padding that gets you on this question. > 2. what …

Member Avatar for Radical Edward
0
140
Member Avatar for erka4444

remove_if only knows the name of the method, but the class defines two methods by that name. So remove_if cannot decide which one to call. You can disambiguate with a cast to the more suitable predicate. [code] particleContainer.remove_if((bool(*)(const Particle&))Particle::isDead); [/code]

Member Avatar for mrnutty
0
191
Member Avatar for Covert06

There is still overflow. When building an intermediate value, it is safest to stop before the least significant digit of the largest possible value, then you can test the intermediate value and next digit separately for overflow. [code] #include <cctype> #include <climits> #include <iostream> int main() { const unsigned safe_value …

Member Avatar for Covert06
0
240
Member Avatar for gerard4143

> Why does a C program treat a function call to a function and a function call to a function pointer the same? Because they *are* the same. :) A function name is converted to a pointer to a function before the call operator is applied. [quote=C99 Draft] The expression …

Member Avatar for gerard4143
0
176
Member Avatar for seebharath
Member Avatar for tomtetlaw

Break it down into a while loop and the problem stands out more. [code] com = cmd.commands; while (com->name) { free(com); com = com->next; } [/code] The code frees com and then immediately uses the freed pointer to reset itself. Freed pointers are off limits, all you are allowed to …

Member Avatar for Radical Edward
0
60
Member Avatar for idlackage

fgets() stores newlines because the absence of a newline is how fgets() tells the caller that only a partial line was read. The comparison is failing because the line contains "RESET\n" instead of "RESET". The usual way to get around a problem like this is trimming the newline. [code] while …

Member Avatar for Radical Edward
0
98
Member Avatar for moqbel

Network status information can be gathered from the network adapters on the machine. Here is a sample that does it on Windows to give you ideas. [code] // Compiled and run with Visual C++ 2010 #include <cstdlib> #include <iostream> #include <vector> #include <windows.h> #include <iphlpapi.h> #pragma comment(lib, "IPHLPAPI.lib") int main() …

Member Avatar for Nick Evan
0
105
Member Avatar for raghum87

XML is the way to go, baby! Store the form state in a separate object, then serialize that object using XmlSerializer. Separating form data from the form class makes this easy, and here is a class that makes the serialization even easier than it usually is. ;) [code] using System.IO; …

Member Avatar for kvprajapati
0
154
Member Avatar for ahaykal

If the number of students is not too big, you can load them all into memory. Then it is easy to work with non-sequential data. [code] #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> using namespace std; struct Student { string Id; string Name; vector<int> Grades; Student() {} …

Member Avatar for ahaykal
0
107
Member Avatar for AspiringCoder

The string class and all of the STL container classes grow dynamically. What are you trying to do that those classes cannot accomplish.

Member Avatar for mrnutty
0
144
Member Avatar for Alerwiali

Fun problem. :) Solving it brute force is easy though. Just go through every element in the big matrix and look for a sub matrix starting at that point. [code] foreach row in bigMat foreach col in bigMat currRow = row for i = 0 to smallMat.Rows currCol = col …

Member Avatar for Alerwiali
0
67
Member Avatar for benji_k

The assignment operator works right to left. [code] <target> = <source>; [/code] All of the assignments in the posted code are flip flopped.

Member Avatar for benji_k
0
106
Member Avatar for albertkao

Have you profiled the running program and confirmed that there is a bottleneck? Why optimize if the program is fast enough already? :)

Member Avatar for Rajesh R Subram
0
110
Member Avatar for Crak

For testing heap memory you can manually throw std::bad_alloc in standard C++ or System::OutOfMemoryException in C++.NET. For stack memory, calling an unconditionally recursive function will eventually overflow the stack.

Member Avatar for daviddoria
0
112
Member Avatar for ryan858

[QUOTE=firstPerson;1240812]Also subtle but still there, this part : [code] char* argv[1] [/code] creates a array of char pointer, with size 1, thus only index 0 is valid. That means that this code :[code] string arg = argv[1]; [/code] is a index out of bounds.[/QUOTE] The array size in a function …

Member Avatar for Aranarth
0
86
Member Avatar for toddermohan

> why they are using *fp Edward assumes you mean why is it [CODE]FILE *fp = fopen(...)[/CODE] instead of [CODE]FILE fp = fopen(...)[/CODE] Under the hood, it looks kind of like the following. [code] struct FILE { HANDLE h; /* System file handle */ BUFFER b; /* I/O buffer */ …

Member Avatar for Radical Edward
0
119
Member Avatar for dmr9215

If array input works and file input does not, the strings you are getting from file are not the same as expected, or you are not searching for a string that was in the file. Verify your data before troubleshooting the hash table.

Member Avatar for Radical Edward
0
148
Member Avatar for niemo

There is probably a .NET method for this, but Edward's first thought was to do it manually with a dictionary. [code] public string MostFrequent(string[] arr) { var freq = new Dictionary<string, int>(); Array.ForEach(arr, s => freq[s] = freq.ContainsKey(s) ? freq[s] + 1 : 1); return (from x in freq orderby …

Member Avatar for EricTetz
0
1K
Member Avatar for LevyDee

As far as the node definition goes, sure. But even though there are two pointers, the use of those pointers is conceptually very different.

Member Avatar for Radical Edward
0
77
Member Avatar for daniel88

> 2 - I request a line of input, as per the first function. Crash! Bang! Why you say crash, do you mean the program crashes? Can you walk Ed through each step with the input and output? Or better yet, post a short program that Edward can run to …

Member Avatar for daniel88
0
141
Member Avatar for bsse007

> I would use an std::map. Unless the problem is likely to become more general, there is no need for the overhead of a map. [code] int count = 0; char c; while (fin.get(c)) { if (c == 'A') ++count; } cout << "There are " << count << " …

Member Avatar for Radical Edward
0
127
Member Avatar for speedy94519

scanf's %s specifier stops reading on whitespace. If you want to read a string with embedded whitespace, fgets is the better option. That way you can read a whole line and then continue to parse it if needed. [code] #include <stdio.h> #include "practice.h" #define TWENTY_FIVE 25 int main () { …

Member Avatar for speedy94519
0
142
Member Avatar for Kombat

> scanf("%s", &exp); This line is the problem. First, exp is an uninitialized pointer. As soon as scanf begins writing characters to whatever address exp points to, a segmentation fault is likely. Next, scanf stops reading on whitespace for the %s specifier. With your sample data of "35x + 17y …

Member Avatar for Radical Edward
0
102
Member Avatar for n30h4x

There are two versions of PDF: the old proprietary format and the newer XML based format. If you do not support the old format, and have the balls to do it manually, any XML library will work. Otherwise, LibHaru might be a start. Ed has not worked with PDF in …

Member Avatar for n30h4x
0
127
Member Avatar for GAME

You can open the form as a dialog using formObj.ShowDialog(). But that makes the form modal and you cannot navigate away until it is closed. You can also set the ShowInTaskbar property to false for a non-modal form that does not show up in the task bar. If you really …

Member Avatar for GAME
0
93
Member Avatar for gameon

This [URL="http://msdn.microsoft.com/en-us/library/bb776891%28VS.85%29.aspx"]MSDN article[/URL] might be helpful.

Member Avatar for Radical Edward
0
203
Member Avatar for mithunp

The problem has to do with modifying a copy of the pointer. Pointers work the same way when it comes to passing by reference as everything else. If you want to change what the pointer points to, another level of indirection is needed. Why? Because *everything* is passed by value …

Member Avatar for Radical Edward
0
156
Member Avatar for c++_fem

What you call variations are normally called combinations with repetition. Here is a sample program for you that does a subset of what you want. It is not be hard to extend the code to use an arbitrary list of values from a file, but Ed does not want to …

Member Avatar for c++_fem
0
2K
Member Avatar for bobsta

std::vector has a back() method that returns a reference to the last element. You are using push_back() to add elements, so the last element will be the most recent. [code] bObjArray.back().header.push_back(currentLineInFile); [/code] at() should work too, as long as the index is bObjArray.size()-1. Edward would need more code to say …

Member Avatar for mrnutty
0
145
Member Avatar for iamthwee

[code] #include <iostream> #include <windows.h> int main() { WIN32_FIND_DATA info; HANDLE file = FindFirstFile("*.txt", &info); if (file != INVALID_HANDLE_VALUE) { struct FileInfo { HANDLE h; WIN32_FIND_DATA info; } newest; newest.h = file; newest.info = info; while (FindNextFile(file, &info)) { if (CompareFileTime(&info.ftLastWriteTime, &newest.info.ftLastWriteTime) > 0) { newest.h = file; newest.info = …

Member Avatar for Radical Edward
0
1K
Member Avatar for sailee

> I dont like to use recursion, unless it is very much necessary Don't fear recursion, it's cool! ;) Actually, Ed doesn't use recursion either unless it makes the code much shorter or simpler. It's a great tool if you know when to use it and more importantly, when not …

Member Avatar for hk<3ob1993
0
195
Member Avatar for smnadig

strtok ignores empty fields. Edward would recommend using another solution, like strcspn and some method of reading or copying a substring: [code=c] #include <stdio.h> #include <string.h> int main() { const char *str = "source,desti,string1,,string3"; const char *delims = ","; size_t start = 0; while (str[start] != '\0') { size_t end …

Member Avatar for ABuNeNe
0
228
Member Avatar for nagaa

fgets reads a single line of characters, but fread reads a block of unidentified objects. fgets uses '\n' as a delimiter, but fread doesn't inspect any of the objects so it relies on a limit of the number of objects. If you're using fread to read string data, the only …

Member Avatar for molu mammen
0
3K
Member Avatar for Radical Edward

One problem with C# is that if you want to modify a collection, you have to manually iterate over it. The generic List class supports ForEach, but there's no method that allows global list changes. C# is kind of restrictive in what changes you can make while iterating, so Edward …

0
210
Member Avatar for Radical Edward

Edward designed this class as a poor man's named property initializer using syntax similar to C99's designated initializers if they worked in a C++ constructor call: [code] Person me( .FirstName="Radical", .LastName="Edward", .Age=23 ); [/code]

0
268
Member Avatar for kartik14

On the main IDE window's menu bar choose Project -> {project name} Properties. That opens the project's property pages. You can specify command line arguments under Configuration Properties -> Debugging -> Command Arguments. Just type in exactly what you would type at the command line after the program name. If …

Member Avatar for tona70
-1
526
Member Avatar for cicigirl04

>I get a error if I don't have ; after else statement, before sum = 0 [code] else [COLOR="Red"](number < 0)[/COLOR] [/code] The else statement doesn't have a condition; the condition is implied by the accompanying if and else if clauses: [code=cplusplus] if (number >= 0) cout << "Invalid Entry! …

Member Avatar for DaJoker
0
283
Member Avatar for chiwawa10

Edward's first guess without seeing the code is that you corrupt your memory somewhere and Vista is better at catching it with a hard failure, or you're just getting lucky on XP. But without seeing the code, all Ed can do is guess.

Member Avatar for Salem
0
118
Member Avatar for RayvenHawk

[QUOTE=RayvenHawk]Any reason why my stack is displaying backwards??[/QUOTE] That's how a stack works, it's a "last-in, first-out" structure. The item at the top will always be the last item that was pushed: [code=cplusplus] #include <iostream> #include <stack> int main() { using namespace std; stack<int> st; for (int i = 0; …

Member Avatar for Radical Edward
1
3K
Member Avatar for Alex Edwards

The only thing Edward can think of is using a union like that isn't required to work even if the conversion is safe but a reinterpret_cast<> is. The rules say that assigning to one member of a union and then accessing a different member right away is undefined behavior.

Member Avatar for vijayan121
0
2K
Member Avatar for edouard89

[code] [COLOR="Red"]// Star is in the wrong place[/COLOR] void Field::*data(){ return NULL; } [COLOR="Red"]// Star is in the wrong place // void* is the wrong return type[/COLOR] void Field::*clone() const{ return NULL; } [/code] The class name and scope operator go right next to the method name, after the return …

Member Avatar for edouard89
0
296
Member Avatar for acejames1

According to the rules, you can't post anything related to pirated programs. Edward would assume that includes linking to sites that offer cracked software.

Member Avatar for Alex Edwards
0
215
Member Avatar for MattEvans

[QUOTE=MattEvans]- Is there any way to tell if an i/ostream passed to a function has been opened in binary or text mode? [/QUOTE] Not directly through the object by default. The easiest solution if you need that information is to pass it along with the object as a parameter. To …

Member Avatar for MattEvans
0
192
Member Avatar for daviddoria

[QUOTE=daviddoria]I have been using vector in c++ lately, but I needed to speed up my code a bit so someone recommended I use regular arrays.[/QUOTE] Using arrays instead of vectors only saves you the overhead of C++'s object model, especially if you need a dynamically sized array. Instead of playing …

Member Avatar for ArkM
0
150
Member Avatar for Lukezzz

The starting form is the first form that's opened. If you're using code generated by the new project wizard there will be a *.cpp file named the same as your project. That's where main() is, and in main() you'll see something like this: [code=cplusplus] // Create the main window and …

Member Avatar for Lukezzz
0
119
Member Avatar for Alex Edwards

[QUOTE=Alex Edwards]What I want to understand is how to have better control of data and how it is represented in a class, structure, union or namespace. Basically a recommendation for a book that really goes in depth on how data is represented in all possible data containers.[/QUOTE] One of Ed's …

Member Avatar for Alex Edwards
0
162
Member Avatar for Rawfel

[QUOTE=Rawfel]It feels like it's very inefficient coding considering the program has to repeat the same arithemtic argument for every "cout" and that's why I ended up posting this, I want to know whether it can improved without getting to advanced.[/QUOTE] If you use the same expression more than once, you …

Member Avatar for Ancient Dragon
0
176
Member Avatar for Risame

Try using the fully qualified name to make sure you've made the namespace visible for the <string> header: [code=cplusplus] std::string q; [/code]

Member Avatar for Radical Edward
0
253
Member Avatar for ichigoSJ

That looks like a fun little program. :) To make it do both addition and subtraction, you need to determine what changes between the two paths. Edward sees that you need to display a different character for the equation--either '+' or '-' so the user knows how to figure the …

Member Avatar for Radical Edward
0
116

The End.