6,741 Posted Topics

Member Avatar for moonL!ght

Did you include the <string> header? Do you have a [icode]using namespace std[/icode] or using [icode]std::string[/icode] somewhere prior to your usage of the string name?

Member Avatar for moonL!ght
0
126
Member Avatar for Pral

[B]>while((fscanf(ifile,"%s%d",m.ip,&m.num))!=EOF)[/B] I'd start with the fact that when fscanf is called, m.ip is an uninitialized pointer. On a side note, using EOF as the test against fscanf isn't wrong, but it's not completely right either. One test case where your condition fails is if the string reads successfully, but the …

Member Avatar for Pral
0
256
Member Avatar for Garrett2011

[B]>Now may a compiler optimize that to constant value so that it'll be the same as following?[/B] Yes. Will it? Probably not. The only meaningful optimization here is memory footprint, and then only for the handful of types that are likely to be smaller than a reference. It's not worth …

Member Avatar for Narue
0
138
Member Avatar for widapol

[B]>The largest number of elements an array can hold in C is whatever your implementation defines size_t as...[/B] 65535 bytes is the minimum size for an object, so you're guaranteed to have an array of sizeof(array)/sizeof(array[0]) <= 65535. Beyond that you enter the realm of non-portable where hitting runtime stack …

Member Avatar for gerard4143
0
205
Member Avatar for Fbody
Member Avatar for Fbody
0
93
Member Avatar for kn_jee

>void main(){ It's [INLINECODE]int main ( void )[/INLINECODE], and you have to return a value (0 is a common choice). No excuses. >gets(string); You took the time to make your array nice a big with extra room for a null character at 1001, and then destroyed all of that work …

Member Avatar for md_azaz1
0
402
Member Avatar for modaslam

>this will be considerably faster if only because it uses just one "printf" statement Somehow I doubt that you'll notice much difference, especially since in saving calls to printf, you added calls to malloc, free, gets, atol, memset, and a statistically significant number of mathematical operations. Not to mention that …

Member Avatar for heznenkiah
0
110
Member Avatar for usep

In the interests of getting the OP in trouble with his teacher for plagiarism: [code] #include <cctype> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <string> namespace { const int MONTHS = 12; const int MONTH_NAME_MAX = 9; static const char *whitespace = " \t"; static const char *separators …

Member Avatar for usep
0
128
Member Avatar for UberJoker

[B]>They seem kind of similar in the sense that both need balancing, >but how different are they when it comes to coding them?[/B] Barring the fact that they're both trees and they're both balanced, AVL and B-Trees are quite different. The biggest difference is that B-Trees usually have a higher …

Member Avatar for dilkash
-1
1K
Member Avatar for xiansen

It'll help if you pass the address of the two objects to a function: [code] void swap(int *a, int *b) { // Swap the objects pointed to by a and b } int main() { int x = 10; int y = 20; swap(&x, &y); } [/code] This way you …

Member Avatar for xiansen
0
197
Member Avatar for Ghost

>Ahh, I see, you work for a company If freesoft is a professional Java programmer and still isn't comfortable with simple arrays, we have cause to be worried.

Member Avatar for masijade
0
614
Member Avatar for neoraghav

[B]>The following code swaps values between 2 variables without using a temp variable.....[/B] Actually, it invokes undefined behavior and could really do anything. If you add sequence points between the operations, then the code is technically correct: [code] a ^= b; b ^= a; a ^= b; [/code] Figure out …

Member Avatar for neoraghav
0
4K
Member Avatar for maharjun

[B]>I observe that the output it gets done only when cin.get(...) is being executed dunno why.[/B] Because cout is tied to cin. When you make an input request on cin, cout is automatically flushed. [B]>please tell me a way to empty(forcefully output) a buffer at will.[/B] There are a number …

Member Avatar for Narue
0
122
Member Avatar for starpointer123

[B]>The errors are that IdNode has no member named 'end', 'begin' and 'push_front'. Help guys.[/B] The errors are correct. IdNode indeed has no member named end, begin, or push_front. Your list class does though, so you probably wanted idList to be an object of the list class rather than the …

Member Avatar for starpointer123
0
188
Member Avatar for cogitoergosum18
Member Avatar for Stefano Mtangoo
Member Avatar for josirucu

>binary gave me enough trouble. Binary search is leaps and bounds more complex than sequential search. Start at the beginning, and go to the end. If you find a match, stop. What's so hard about that? You probably solved the first half of the problem when you printed the sorted …

Member Avatar for foxpro21
0
349
Member Avatar for maharjun

[B]>DOES PERFORMING DELETE OPERATION ON A DANGLING POINTER LEAD TO INSTABILITIES?[/B] When you delete an indeterminate pointer, demons fly out of your nose and kill a kitten.

Member Avatar for mike_2000_17
0
1K
Member Avatar for gwahl
Member Avatar for Ajith007

If your project is to implement the code, why do you think stealing it from someone else doesn't constitute cheating?

Member Avatar for Adak
0
297
Member Avatar for ana12

Seeing as how it just started, fine. Though I have heaps of work to do and approaching deadlines, so I'm anticipating a stressful day of work followed by an equally stressful weekend of work.

Member Avatar for Kusanagi03
0
102
Member Avatar for myk45

[B]>You know this is written in C not C++... [/B] You know that this compiles as C++ too...oh, apparently not. :icon_rolleyes:

Member Avatar for myk45
0
219
Member Avatar for myk45

Please don't create a new thread with the same question. Cross posting is just as bad as posting in the wrong place (if not worse). Instead, flag your own thread as bad with the note "this belongs in so and so forum, please move it" for the moderators. Then they …

Member Avatar for myk45
0
87
Member Avatar for Invecta

For various reasons, strings don't work like you expect in C. It's really best to simply see strings as arrays with a special value at the end, and treat them accordingly. For comparison, the strcmp function in <string.h> is what you would typically use to compare two strings: [code] if …

Member Avatar for justiceigwe
0
87
Member Avatar for Duece_68

It's evaluated as ((3 + (2 * 3)) + 2), not ((3 + 2) * (3 + 2)). If you don't wrap your macro arguments in parentheses, you may not get the evaluation order you wanted.

Member Avatar for arkoenig
0
151
Member Avatar for neil_mahaseth

While people can use terminology however they like, I've never seen "sorted linked list" and "ordered linked list" mean two different things. They've always been interchangeable.

Member Avatar for Narue
0
201
Member Avatar for timb89

A loop invariant is an assertion that doesn't change between the beginning of the loop and each iteration. In your code, one such assertion is that for any a[x] where x < i, target does not exist. This invariant is true prior to executing the loop because x would be …

Member Avatar for Narue
0
152
Member Avatar for francez
Member Avatar for abhiab1991

Those are neither doubts nor questions. I doubt your intentions are anything but those of a cheater looking for free code to get through assignments without any effort. I also doubt that helping you would be anything but a waste of my time because you'll do one of two things: …

Member Avatar for abhiab1991
1
133
Member Avatar for daviddoria

[B]>Why is there not a <heap> just as is there is a <set>, etc?[/B] <priority_queue>, perhaps?

Member Avatar for Narue
0
106
Member Avatar for timb89

You're essentially using a recursive algorithm without the recursion. Might I suggest [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_bst1.aspx"]this tutorial[/URL]?

Member Avatar for timb89
0
173
Member Avatar for Garrett2011

[B]>Is there any way to inline just some selective calls to a particular function not all of them?[/B] Manually inline it. Of course, that defeats the purpose of a function, so I wouldn't generally recommend it. [B]>how much authority for making a function inline or not is there for the …

Member Avatar for Narue
0
155
Member Avatar for ziggystarman

I take it you've already exhausted the tutorials and documentation on the Boost site?

Member Avatar for ziggystarman
1
236
Member Avatar for SgtMe

Provided the items are separated by whitespace, you can use the simplest form of stringstream I/O to break it apart: [code] #include <iostream> #include <sstream> #include <string> int main() { std::stringstream split("v 0.200006 -0.093641 0.584690"); std::string token; while (split>> token) std::cout<< token <<'\n'; } [/code]

Member Avatar for SgtMe
0
171
Member Avatar for RickSMO
Member Avatar for RaoxFaello

cin's >> operator is type specific. If you give it an int, it will try to parse an integer, and fail if the conversion can't be made. So you would need to check for errors during the input request itself. A not uncommon pattern is an input loop that continues …

Member Avatar for Narue
0
144
Member Avatar for tongdl04

You can reuse an ifstream object, but take note that opening and closing files does not affect the stream state. If you open a file, read to EOF, close the file, then open another file, the eofbit will still be set. So do something like this: [code] ifstream in("first file"); …

Member Avatar for tongdl04
0
559
Member Avatar for gju

What did you try? While it's straightforward, the exact method depends on the result you want.

Member Avatar for abhimanipal
0
126
Member Avatar for gaurav_13191

[B]>instead of using malloc(), use calloc() and you don't have to do (*ptr)->link=NULL;[/B] I wouldn't recommend relying on that. calloc zero fills the bytes, and a null pointer isn't required to be represented by all bits zero. [B]>Anyways, as for why its not working, beats me.[/B] It [i]is[/i] working, he …

Member Avatar for N1GHTS
0
559
Member Avatar for The physicist

[B]>mktime ( timeinfo );[/B] I suspect you want this: [code] rawtime = mktime(timeinfo); [/code] Likewise with rawtime2. Otherwise both will be close enough to the same time (the running time of the program) to compare as 0 seconds.

Member Avatar for The physicist
0
838
Member Avatar for gju
Member Avatar for frogboy77

[B]>In other words b will have no limit will just break when a^b is too large.[/B] Then it still has a limit. You can use an arbitrary length math package like [URL="http://gmplib.org/"]GMP[/URL] to get around the limitation. Alternatively, pow checks for out of range requests for you, sets errno appropriately, …

Member Avatar for frogboy77
0
90
Member Avatar for kashifboy

[B]>There is no way to be sure that the input you received is in integer format.[/B] No standard way, at least if you want to force integer input at the keystroke level. If you can get raw input, you can force the user to enter whatever you want. In this …

Member Avatar for Narue
0
100
Member Avatar for Dazaa

[B]>Is that a strong enough reason not to cast your malloc results to your target?[/B] No, but I find not needing to type out a redundant cast and not needing to mention the target data type at all somewhat compelling: [code] p = malloc(N * sizeof *p); [/code] [B]>I always …

Member Avatar for sree_ec
0
178
Member Avatar for senche

[B]>Need some examples for non Ansi C Stanadard.[/B] When someone says something like "Non-ANSI", they usually mean pre-standard C (often the K&R variant). If you want to be picky, the current C standard is non-ANSI because ANSI no longer controls the C standard, ISO does. If you want examples, [URL="http://cm.bell-labs.com/cm/cs/who/dmr/chist.pdf"]this[/URL] …

Member Avatar for N1GHTS
0
993
Member Avatar for Layla_2401
Member Avatar for joneil001
0
2K
Member Avatar for Kafana

Borland 4.5 is very old. I'd recommend upgrading to a modern compiler such as Visual C++ Express or Code::Blocks (assuming you want a free option). Presumably you'll be working on a Windows platform, so a quick foundation in the Win32 API will get you started toward writing GUIs.

Member Avatar for Narue
0
150
Member Avatar for onus

[iCODE]s[/iCODE] is a null pointer. Your code is actually pretty horrible, but the null pointer dereference is your immediate problem.

Member Avatar for N1GHTS
0
518
Member Avatar for burcin erek

[B]>error message is seen on the goto statement. did I miss library ?[/B] goto is a part of the core language, not a library feature. If you're getting an error, you used it wrong. Looking at your code, you clearly don't understand the concept of goto, so I'd suggest going …

Member Avatar for burcin erek
0
225
Member Avatar for akmalhisyam

When you don't pass any arguments to ignore, it reads and discards the next character. In your case, that would be the newline character ('\n'). There's a sticky that explains the issues involved (translation: I don't want to write it all again).

Member Avatar for akmalhisyam
0
3K

The End.