436 Posted Topics

Member Avatar for anupjp
Member Avatar for doublebond

Hash functions can handle more than just integers. The generic algorithms can hash any collection of bytes you give them: [code=cplusplus] unsigned int hash(void *key, int sz) { unsigned char *p = (unsigned char*)key; unsigned hval = 0; for (int x = 0; x < sz; ++x) { hval = …

Member Avatar for Tom Gunn
0
122
Member Avatar for edenn1
Member Avatar for 9868

[QUOTE]So q+1 is address immediately after the 50 elements but how does the type casting affects the output.[/QUOTE] Pointer subtraction takes the size of the type into account. If it's a pointer to char, the size is 1 and with 50 chars the result will be 50. If it's a …

Member Avatar for Tom Gunn
0
91
Member Avatar for OffbeatPatriot

You could probably dig around and figure out what the problem is, but an easy first step is to reinstall/repair Visual Studio. Make sure the installation is clean before doing any crazy troubleshooting. It could just be a corrupt DLL or two. :)

Member Avatar for OffbeatPatriot
0
592
Member Avatar for monkey_king

All strtok does is replace the delimiter with '\0'. If you skip over it, you'll find the rest of the string: [code=c] #include <stdio.h> #include <string.h> int main() { char s[] = "a|b|c|d|e|f|g"; char *tok = strtok(s, "|"); printf("%s\n%s\n", tok, tok + strlen(tok) + 1); return 0; } [/code] The …

Member Avatar for jephthah
0
3K
Member Avatar for mrinal.s2008

[QUOTE]2. In the above code snippet, when I define class Sampler as a local class, g++ shoots an error. Why is it that compiler works fine with vector vec3's declaration when class Sampler is global and shoots an error when Sampler is local to main?[/QUOTE] It is just one of …

Member Avatar for jencas
0
103
Member Avatar for 9868

[QUOTE]Basically it comes down to this: If you don't either (1) prototype the function or (2) fully define the function prior to its use[/QUOTE] Simplify, my friend. :) A function definition is also a prototype, so you don't need to split them up. As long as there is a prototype …

Member Avatar for jephthah
0
291
Member Avatar for Ancient Dragon

The tutorial tells you what to do to compile as Managed C++ instead of C++/CLI: [QUOTE][B]Note [/B]In Visual C++ 2005, you must add the common language runtime support compiler option [B](/clr:oldSyntax)[/B] to successfully compile the previous code sample as Managed C++. To add the common language runtime support compiler option, …

Member Avatar for Ancient Dragon
0
195
Member Avatar for edenn1

Linked lists can be sorted just like arrays as long as you only use sequential access. Pick a sort algorithm that only looks at adjacent nodes at any given time and it'll work for lists. You don't need to monkey with links either, just swap the data. This is a …

Member Avatar for Tom Gunn
0
107
Member Avatar for Pavan_

[QUOTE]On gcc compiler, 2nd and third printf() call taking value of i and j automatically.. but if in first printf() call ,i don't give i and j as argument then that prints garbage value.. can nyone explain it plz..[/QUOTE] It happens to work out that way with how printf and …

Member Avatar for Tom Gunn
0
149
Member Avatar for reyaanhelp

[QUOTE]I'm a beginner and trying to convert this code in class.[/QUOTE] It's already a class. The only difference between struct and class in C++ is the default access rights. struct is public by default and class is private. [QUOTE]kindly do it for me.[/QUOTE] Sorry my friend, but it doesn't work …

Member Avatar for csurfer
0
457
Member Avatar for zeus1216gw

[QUOTE]Is there a 'z' involved, as in the total number of groups?[/QUOTE] z can be calculated using x and y, but having an actual z makes it harder to handle an x that isn't perfectly divisible by y.

Member Avatar for csurfer
0
116
Member Avatar for cooolguy

What don't you understand? I could write pages and pages explaining what's happening, but that won't help as much as a pointed answer to a pointed question. ;)

Member Avatar for cooolguy
0
75
Member Avatar for penguhooks

Except for deleting line 15, what Ancient Dragon wants you to do will make your code more portable. That's a good goal, but you have a real problem to fix first: integer overflow. p, r and t can't be very big before multiplying them together will overflow an int, and …

Member Avatar for Tom Gunn
0
309
Member Avatar for lotrsimp12345

search is a standard name declared in the <algorithm> header. It's a very bad idea to use standard names even if you don't include the header because other standard headers could include it. Try capitalizing your class from search to Search, or put it in a namespace.

Member Avatar for smart_pc
0
226
Member Avatar for ermithun

Assuming that [ICODE]return B;[/ICODE] should be [ICODE]return ptr;[/ICODE], there shouldn't be a segmentation fault. The memory doesn't go away until your code deletes it. As long as you have a pointer to the memory, it's safe to access. But if you don't ever delete it, that could cause a memory …

Member Avatar for ermithun
0
101
Member Avatar for _dragonwolf_

[QUOTE]I have no clue as to how to start or even where to start.[/QUOTE] Then you're thinking about it the wrong way. Whenever you get overwhelmed with a problem, the problem is too big and needs to be broken down into smaller problems. Instead of doing everything, just open and …

Member Avatar for jephthah
0
123
Member Avatar for doublebond
Member Avatar for DoEds
Member Avatar for walter clark

[ICODE]Assembly::GetExecutingAssembly()->Location;[/ICODE] will give you the full path of the running program. The 'file date' isn't specific enough. Do you want the creation time, the last read, last write? But the File class has that stuff: [code=cplusplus] String^ path = Assembly::GetExecutingAssembly()->Location; DateTime^ fileDate = File::GetCreationTime(path); [/code]

Member Avatar for walter clark
0
135
Member Avatar for warp

I generates undefined behavior. [ICODE]new[/ICODE] goes with [ICODE]delete[/ICODE] and [ICODE]new[][/ICODE] goes with [ICODE]delete[][/ICODE], you can't mix them. But in practice it will cause a memory leak for the first delete, and probably also a crash when you try to delete the second time.

Member Avatar for warp
0
122
Member Avatar for akulkarni

The string is only a palindrome if the characters match all of the way through. Your flag should be changed in the loop if the test fails, and you can also break from the loop because there's no need to continue checking a failed palindrome: [code=c] int different = 0; …

Member Avatar for csurfer
0
8K
Member Avatar for mexx

Stupid question: if it works for set<>, why not use set<> instead of hash_set<>? I know it's the difference between a balanced BST and a hash table, but if set<> isn't too much slower you should use the way that works right now instead of fix something broken.

Member Avatar for zdeepblue
0
317
Member Avatar for Hiroshe

[QUOTE][CODE]return *output;[/CODE][/QUOTE] That line is really the whole problem. [ICODE]*output[/ICODE] is not a pointer to char, it's a char. You're also trying to return a pointer to a local array. When the function returns, the local array goes bye bye and you can't use a pointer to it anymore. Try …

Member Avatar for Hiroshe
0
142
Member Avatar for MrNoob

Take the pattern out of it and do a simple triangle: [code] F FF FFF FFFF FFFFF FFFFFF [/code] You can add another variable that counts down without changing how the loops work in the triangle code: [code] for x = 1 to 6 for y = 0 to x …

Member Avatar for MrNoob
0
229
Member Avatar for TrintiyNoe

[QUOTE]Yeah thats exactly what i wanted,sad to know not possible[/QUOTE] What you want is called reflection. C++ has a very limited type of reflection in the RTTI stuff, but it doesn't work for variable names because variable names are lost during compilation. You have to map input strings to objects …

Member Avatar for TrintiyNoe
0
125
Member Avatar for TrintiyNoe

[QUOTE]but i thought it would be easier if there is one simple way doin like a function or somethin.[/QUOTE] You can write your own function to do it. :) But doing it in a general way is not as easy as you thing. Removing all spaces is easy but leaving …

Member Avatar for Tom Gunn
0
156
Member Avatar for u8sand

Tutorials only go so far. You need a [URL="http://www.amazon.com/Programming-Windows%C2%AE-Fifth-Microsoft/dp/157231995X"]good book[/URL] and a [URL="http://msdn.microsoft.com/en-us/library/default.aspx"]comprehensive reference[/URL].

Member Avatar for u8sand
0
105
Member Avatar for hypernova

[QUOTE]1. Difference between memory allocation of local and global (or other static variables)....? (or why i cant initialize a global variable more than once outside main and all other functions) 2. Holes in structures, and structures and pointers. 3. Deep concepts in pointers, objects, classes.....i mean relation between pointers and …

Member Avatar for Tom Gunn
0
147
Member Avatar for ermithun

I don't know what signal 368 is, but if the segmentation fault is happening in list::erase(), you can search for where you call it and stop there in a debugger to see what's up. Maybe you're passing list::end() or an invalid iterator as one of the arguments.

Member Avatar for Tom Gunn
0
116
Member Avatar for TrintiyNoe

[QUOTE]use string stream in general and use atoi if speed is an issue.[/QUOTE] That's close to my advice. But I say use strtol because atoi doesn't have any error handling capability. Boost:lexical_cast and Boost::numeric_cast are even simpler than ad hoc string stream code or robust strtol code, but you have …

Member Avatar for TrintiyNoe
0
128
Member Avatar for serkan sendur

[QUOTE]I thought you were from USA, what nationality are you?[/QUOTE] Military service in the US hasn't always been voluntary. The draft only stopped around 1980.

Member Avatar for MosaicFuneral
0
210
Member Avatar for dorkwad

[QUOTE=dorkwad;903681]Hey,new to stl, in c array, we can declare an array like [CODE]int a[]={2,4,5,6,7,7}[/CODE] how can u do it for a vector without pushing back n times???[/QUOTE] C++0x has extended initializer lists, but current standard C++ doesn't allow it for the vector class without tricks like siddhant3s'. [URL="http://www.boost.org/doc/libs/1_39_0/libs/assign/doc/index.html"]Boost::Assign[/URL] can make …

Member Avatar for Tom Gunn
0
96
Member Avatar for Pramoda.M.A

There is no point in understanding the output. It's [URL="http://en.wikipedia.org/wiki/Undefined_behavior"]undefined behavior[/URL]. The output could be different the next time you run the program. UB also makes the rest of the program undefined so you have to understand all of that craziness too. It's a waste of resources to understand UB, …

Member Avatar for csurfer
0
150
Member Avatar for timos

[QUOTE]Why is it? I am probably missing something very simple here.[/QUOTE] Something subtle, yes. References are not pointers, even though internally they might be implemented using pointers. When you have a reference to an objects, members are accessed the same way as with regular objects.

Member Avatar for athlon32
0
126
Member Avatar for tomtetlaw

[QUOTE=tomtetlaw;902948]this is of topic but, how come the size of thing is called an operator if it takes a parameter?[/QUOTE] It doesn't take a parameter, it takes an expression as the operand. Expressions can be surrounded with redundant parentheses: [code=cplusplus] double d; float f; sizeof d; // no redundant parentheses …

Member Avatar for siddhant3s
0
133
Member Avatar for arun_354

[QUOTE=tux4life;902898][URL="http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html#SECTION00044000000000000000"]http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html#SECTION00044000000000000000[/URL][/QUOTE] That link is really opinionated. [ICODE]using namespace std;[/ICODE] says that every name in the std namespace is available without having to prefix it with [ICODE]std::[/ICODE]. [ICODE]using std::{name};[/ICODE] says that only the specified name is available without a prefix. Without either of those, you have to prefix every instance of …

Member Avatar for u8sand
0
577
Member Avatar for StaticShell

[QUOTE]I need to write these to a binary file and in binary values (139 = 00110001).[/QUOTE] 139 in binary is 10001011. Are you using a different way of encoding the value as binary? I can show you how to get the bits of a value, but that won't help if …

Member Avatar for StaticShell
0
157
Member Avatar for jessejamesjjr

Open a text file for reading by making an object of the ifstream class. Once it's open and everything is good, you can use it just like cin. Objects of the ofstream class work the same way and can be used like cout: [code=cplusplus] #include <fstream> #include <iostream> #include <cstdlib> …

Member Avatar for jessejamesjjr
0
190
Member Avatar for SP IT

[CODE]while (tryanother = 'y'){[/CODE] [CODE]if (tryanother = 'n')[/CODE] The equality operator is ==. The = operator is for assignment. Those two conditions are the same as these: [CODE]while ((tryanother = 'y') != 0){[/CODE] [CODE]if ((tryanother = 'n') != 0)[/CODE]

Member Avatar for SP IT
0
105
Member Avatar for Hiroshe

[QUOTE]you need memset() to set a default value.[/QUOTE] memset() is not needed. You can do it without calling a function by using an initializer for the array: [code=c] int array[4][2] = {0}; /* init all elements to 0 */ [/code]

Member Avatar for Hiroshe
0
1K
Member Avatar for xyzt

[QUOTE]i couldn't understand the "." format...[/QUOTE] It's one of the new features to C. You can initialize struct members by name instead of by position: [code=c] struct test { int first; int second; int third; }; struct test a = {0, 0, 1}; /* Old way */ struct test b …

Member Avatar for tux4life
0
131
Member Avatar for EvilDavo

I don't think that kind of thing can be taught. You just have to read code to see how other programmers did it and try out things for yourself. The more you do it the better you'll get at it. There's no 'right' way to design OO programs. Nobody can …

Member Avatar for EvilDavo
0
206
Member Avatar for valinux

[QUOTE]Next time, try to elaborate your point so that the other person can comment on it.[/QUOTE] Well, now you know how it feels to get negative rep you don't agree with. No chance to defend, just BAM, hit and run. [QUOTE]Linux is really a good designed OS.[/QUOTE] Linux is a …

Member Avatar for tux4life
0
169
Member Avatar for coachHinesfan

A binary operator is an operator like + or / that have two operands, one on each side. A unary operator is an operator that only has one operand: [code=cplusplus] a * b // binary true && false // binary -1 // unary !x // unary [/code]

Member Avatar for coachHinesfan
0
136
Member Avatar for dzhugashvili

This is the essence of what you're doing: [code=cplusplus] #include <iostream> using namespace std; int main() { int *p[10]; int val = 5; for (int x = 0; x < 10; ++x) p[x] = &val; for (int x = 0; x < 10; ++x) cout << *p[x] << '\n'; val …

Member Avatar for dzhugashvili
0
165
Member Avatar for cmakesmesad

[QUOTE]Did I do it right? the function doesnt seem to be returning anything[/QUOTE] The function doesn't return anything because the return statement is commented away. The function returns a junk pointer. I don't think strtok is the best way to do this because you don't have a good way of …

Member Avatar for Tom Gunn
1
86
Member Avatar for coachHinesfan

So you can do things like [ICODE]a = b++[/ICODE] and [ICODE]a = ++b[/ICODE]. Chaining and combining expressions accounts for most of the weirdness in how operator overloading works. But you don't have to follow the conventions even though it's a good idea to stick to idioms that everyone expects. Your …

Member Avatar for Dave Sinkula
0
338
Member Avatar for wasif005

[QUOTE]but my ans is always "password is wrong"[/QUOTE] Print both strings and eyeball them: [code=cplusplus] cout << ">" << passFromFile << "<\n"; cout << ">" << passFromUser << "<\n"; [/code] There's probably whitespace or something that makes the difference.

Member Avatar for wasif005
0
120

The End.