6,741 Posted Topics

Member Avatar for dimios

[QUOTE]I am trying to figure out the advantages of C++ STL containers over C.[/QUOTE] C++ has STL containers and C doesn't. Case closed, Sherlock. I get the impression that you're building a fallacious argument about C++'s superiority over C, which is a complete waste of time because it lacks objectivity …

Member Avatar for NathanOliver
0
218
Member Avatar for Talguy

[QUOTE]I don't believe there are any times when using this-> is harmful, but there are certainly times where NOT using it can produce an ambiguous case that will cause you headaches.[/QUOTE] Of course, that's assuming you don't use any kind of naming convention. Prefixing/suffixing data members with an underscore or …

Member Avatar for Aranarth
0
116
Member Avatar for Ajantis

[B]>square root of N... N loglogN... N log^2 N... N^2 log N... >and many more. How do I know how those look like?[/B] They're generally not as clear cut as N and N^2 because you typically don't see this kind of loop directly: [code] for (int i = 0; i …

Member Avatar for DarkT
0
351
Member Avatar for C#Coder

>Any ideas why I can't include it? Yes, fstream.h is not a standard C++ header. Nor is iomanip.h. Come to think of it, void main isn't standard either (regardless of what your compiler's documentation says). If you want to go fully standard, use C headers with the .h dropped and …

Member Avatar for sgtjoebear
0
2K
Member Avatar for Kanoisa

You should really reconsider relying on non-portable behavior (eg. fflush(stdin)) and non-portable functions (eg. gets_s) if you can avoid it. I'd also recommend merging your months into an array. Even if you waste a few elements of an array, it's still a win in complexity if you consider nothing more …

Member Avatar for Kanoisa
0
170
Member Avatar for mrnutty

I'll take a look at it for you. You can find my email on my homepage, and my homepage on my Daniweb profile (giving spammers a harder time than simply posting it here).

Member Avatar for mrnutty
0
146
Member Avatar for vbx_wx

[QUOTE]It is posible in a linked list implementation,the nod to hold more then one information ?[/QUOTE] It can hold whatever you want. You're the programmer after all. :icon_rolleyes: However, since most linked list libraries are fairly generic, they'll hold only one item of either template or void* type and that …

Member Avatar for Narue
0
147
Member Avatar for Sandhya212

[QUOTE]stringstreams are a much cleaner solution than dirty C sprintf functions[/QUOTE] Really? The only "dirty" thing I can think of (tedious would be my choice of words) is no std::string support in sprintf. So you need to figure out the maximum size of the file name buffer beforehand. Aside from …

Member Avatar for Sandhya212
0
221
Member Avatar for foco

strlen is declared in <string.h>, or <cstring> if you want your stuff in the std namespace.

Member Avatar for foco
0
115
Member Avatar for phohammer

[QUOTE]Prime_Finder findprimes();[/QUOTE] You've independently discovered a rather subtle problem with C++'s grammar. This line is actually interpreted as a function declaration. The function is called findprimes, has no parameters, and returns and object of type Prime_Finder. To define an object with the default constructor, omit the empty parens: [code] Prime_Finder …

Member Avatar for phohammer
0
173
Member Avatar for Silen

[QUOTE]Is using other then int types is part of the ANSI C?[/QUOTE] The behavior is implementation-defined if you use anything other than _Bool, signed int, or unsigned int.

Member Avatar for Silen
0
133
Member Avatar for gkaykck

It's an order of operations problem. Inside the loop, you're always testing the next pointer in temp, which is always uninitialized. Take some time to test out how for loops manage the counter variable, because a lot of code relies on that behavior and it's easy to write code that …

Member Avatar for gkaykck
0
601
Member Avatar for darkdai

[QUOTE]im tryin to generate random strings and store them in an array. can anyone please show me? [/QUOTE] It's easy if you really want random (pseudorandom) strings from a source: [code] #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void random_fill(char s[], size_t n, const char *src) { size_t src_len …

Member Avatar for Narue
0
122
Member Avatar for Bukhari1986

Just post your code, already. Ideally write up a bare bones program that exhibits your problem without being excessively long. Playing twenty questions is unproductive, especially when the problem sounds like something most of us can solve at a glance.

Member Avatar for Bukhari1986
-2
136
Member Avatar for tenix

Arrays don't grow or shrink. If you need dynamic sizing, use an std::vector instead. In fact, you should prefer std::vector in favor of arrays anyway, because they're easier to work with. [edit: Bah! This is the C forum. Ignore this post]

Member Avatar for tenix
0
16K
Member Avatar for SacredFootball
Member Avatar for ce0

[QUOTE]but then it dont work anymore[/QUOTE] WTF do you mean by "it don't work anymore". Are we to read your mind for sufficient details? I suspect you're encountering a very simple and common problem with scanf not playing nice, but I can't say for sure because in that relatively large …

Member Avatar for Tellalca
0
4K
Member Avatar for God Coder123

Clearly Visual C++ 2010 is smarter in terms of implicit standard headers. You failed to include <string>, and the compiler rightly complains. The others don't complain because <string> is probably included inside one of the other three standard headers you've included, so the bug goes unnoticed.

Member Avatar for God Coder123
0
141
Member Avatar for rajsharma_85

[QUOTE]Are there any known pitfalls in using fread ?[/QUOTE] It's comparatively awkward for reading string data.

Member Avatar for Narue
0
206
Member Avatar for drunkenmonk

[QUOTE]I have written a stack to hold int's before, but never to hold nodes(or whatever it needs to hold...pointers?)[/QUOTE] You'd be holding pointers, and it's really no different from integers in how you use the stack: [code] TNode *stack[64]; int top = 0; [/code] I assume you're implementing an iterator-based …

Member Avatar for Narue
0
91
Member Avatar for phummon

It's very rare when one absolutely [i]needs[/i] to keep everything loaded at the same time. I'd recommend changing your logic so that you only need to keep a few records in memory at once.

Member Avatar for NathanOliver
0
185
Member Avatar for schaden

Define what you mean by "string", because the whole file can be a string, each line can be a string, each word can be a string (for various definitions of "word"), to name three common needs.

Member Avatar for Narue
0
94
Member Avatar for james85

[QUOTE=james85]hi i would like u to tell me if i can make a random function to choose between four numbers and only them(-1 , 1 , -10 ,10)[/QUOTE] Yes, you can. Quite easily, in fact: [code] int a[] = { -1, 1, -10, 10 }; int choice = a[rand() % …

Member Avatar for nbaztec
0
110
Member Avatar for farhanafzal

Start by learning how to calculate a factorial. Then translate that to code. Finally, do that on every value from N to M. Seriously, have you tried [I]anything[/I] yet?

Member Avatar for nbaztec
0
232
Member Avatar for Swiftle

Oddly enough, I posted a [URL="http://www.daniweb.com/code/snippet285300.html"]very basic memory pool[/URL] just the other day that does exactly what you're trying to accomplish. You might find it helpful.

Member Avatar for nbaztec
0
156
Member Avatar for johndoe444

[QUOTE]Why is it not acting correctly?[/QUOTE] Probably because your length parameter is shy by one. Try not subtracting 1: [code] memcpy(temp_str, suf_arr[j].word+1, suf_arr[j].len); [/code] You still want to copy the null character, after all.

Member Avatar for UncleLeroy
0
2K
Member Avatar for CppFTW

[QUOTE=CppFTW]Hi, I was wondering if the compiler Visual C++ is smart enough to optimize code like this: [CODE=C++]string temp = "abcd"; string temp2 = "hahaha"; string temp3 = temp + temp2;[/CODE] "temp + temp2" can be replaced by "abcdhahaha" [/QUOTE] Actually, Visual C++ is smart enough [I]not[/I] to optimize in …

Member Avatar for CppFTW
0
162
Member Avatar for Lorilei

You don't close a thread. Ever. That can only be done by moderators. Why do you want to do this?

Member Avatar for Narue
0
29
Member Avatar for saw77

[QUOTE]isn't it supposed to stop on 5 letters or at least don't memorize these plus letters?[/QUOTE] Why would it? You never told it to do anything of the sort. In fact, it's quite impossible to include those safety measures with the gets function. You simply invoke undefined behavior, and the …

Member Avatar for saw77
0
217
Member Avatar for John Linux

[QUOTE]what is wrong here...[/QUOTE] Side effects, my inquisitive friend: [code] int x = 2; cout<< SQR(x++) <<'\n'; cout<< x <<'\n'; [/code] x is incremented twice due to the macro being nothing more than a textual substitution. Thus the expanded macro is [icode]x++ * x++[/icode].

Member Avatar for Banfa
0
86
Member Avatar for dimios

This reeks of homework, and nobody will do your homework for you. However, I'll offer some clarification where I feel the questions are incorrect. [QUOTE]explain with suitable examples the advantages these [I][container classes][/I] give to the programmer over a procedural language such as C.[/QUOTE] This question exhibits a common misconception …

Member Avatar for bandtank
0
221
Member Avatar for Kesarion

You'll need to hook the keyboard at a low level to manage this. I'd suggest studying software key loggers for ideas. However, generally this kind of functionality is either unnecessary or malicious. Why do you want to process key strokes when the program is inactive?

Member Avatar for nbaztec
0
181
Member Avatar for anuragcoder

There are a number of ways to do it. Here's one: [code] #include <iostream> #include <string> int main() { using namespace std; string text; int nl = 0; cout<<"Press enter twice in a row to quit: "; while (nl < 2 && getline(cin, text)) { if (text.empty()) { ++nl; } …

Member Avatar for anuragcoder
0
2K
Member Avatar for sharensla

[B]>is their any body tell me the Difference between int* a; and int *a; ?[/B] From a language standpoint there's no difference. However, placing the asterisk by the variable makes more sense when you have multiple variables in a declaration: [code] int *p, *q; [/code] The reason this makes more …

Member Avatar for Fbody
0
2K
Member Avatar for Tellalca

[QUOTE]I wonder why the following code work.[/QUOTE] It doesn't. The recursive calls fail to fix the subtree: [code] if(root->data>item) root->left = insert(root->left,item); else if(root->data<item) root->right = insert(root->right,item); [/code]

Member Avatar for Tellalca
0
92
Member Avatar for Narue

In answer to a coworker's question today about memory management today, I wrote the following code. It's an implementation of the gets function that accepts an infinite length string (bounded only by the heap) and [i]does not[/i] force the caller to free the resulting pointer. I figure that it's a …

Member Avatar for Narue
3
378
Member Avatar for albanosali

Good luck. Come back when you have a specific freaking question. :icon_rolleyes:

Member Avatar for tkud
0
87
Member Avatar for james85

[QUOTE]if i press anything else the program prints me the message twice[/QUOTE] Because there are two characters that don't match your condition in the stream. Run your test again and count how many keys you press. I bet you'll discover that one of them is the Enter key.

Member Avatar for Aia
0
149
Member Avatar for myth_terry

[QUOTE]am seriously ready to pay a reasonable amount for this... around $20[/QUOTE] Daniweb is not a programmer rental service. Offering to pay someone to do your homework is the kiss of death around here. [QUOTE]i need to submit tomorrow.[/QUOTE] Congratulations, you've just gotten a lesson in time management from the …

Member Avatar for myth_terry
-3
218
Member Avatar for kavourdoukos

[QUOTE]How can i make sscanf() skip all whitespace characters?[/QUOTE] It's awkward for string data. You might be better off manually extracting the data you want. [QUOTE]eg.->@Solomon Islands ,i need "Solomon Islands" in one string[/QUOTE] The boundary characters matter. I assume the string starts with '@', but if it ends with …

Member Avatar for Narue
0
7K
Member Avatar for cswenson1

popen isn't a standard C++ function, but you'll typically find it as an extension in <cstdio>.

Member Avatar for Narue
0
1K
Member Avatar for moni94

This solution isn't uncommon. Last I heard, a stack of Mac Minis made for a decent load balanced server farm (as opposed to the usual career as a doorstop).

Member Avatar for jwenting
0
112
Member Avatar for Stevishere

[QUOTE=cscgal;1222646]> That being said, we are launching a new design for the site in about a month. I will give it a try at first, not using a modal, and see if all of the activity stats drop off. So the new design has been up and running without the …

Member Avatar for Nick Evan
0
365
Member Avatar for niemo

[URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608"]Clicky[/URL].

Member Avatar for Narue
0
216
Member Avatar for Ja14

[QUOTE]How do I code for various column widths?[/QUOTE] By using an appropriate data structure, reading each line as a whole, and then parsing out the columns. This is C++, so a vector of vectors or something similar would be far less awkward than a dynamic table. As for parsing the …

Member Avatar for Ja14
0
130
Member Avatar for vbx_wx

Data structures implemented [I]using[/I] the STL, or implementing the STL itself?

Member Avatar for Narue
0
180
Member Avatar for ssmg

[QUOTE]however neither of those are C++ they are part of the C standard library and C++ provides the same functionality through the use of stringstreams.[/QUOTE] Just chiming in with a minor correction. atoi and strtol are most certainly C++. You shouldn't buy into the "pure C++" BS that encourages one …

Member Avatar for hypernova
0
432
Member Avatar for Moody_1

This reeks of homework. Please prove that you've tried to solve the problem if you want any help. Being fed an answer doesn't teach you anything except how to be helpless.

Member Avatar for Narue
0
88
Member Avatar for daniel88

I think you're confused about how the insert member function works for the vector class. You'd probably be better off simply using the overloaded subscript operator: [code] productMap[prod->GetCode()] = prod; [/code] [QUOTE][CODE]static map<string, ProductLine*, less<string> > productMap;[/CODE][/QUOTE] [ICODE]less<KeyType>[/ICODE] is already the default predicate, you don't need to specify it unless …

Member Avatar for daniel88
0
163
Member Avatar for yongj

[QUOTE][CODE]getline(cin, line);[/CODE][/QUOTE] You're still pulling from cin. Change that to be your file stream: [code] getline(fileIn, line); [/code]

Member Avatar for Ketsuekiame
0
151

The End.