6,741 Posted Topics
Re: 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? | |
Re: [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 … | |
Re: [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 … | |
Re: [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 … | |
Re: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19[/url] | |
Re: >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 … | |
Re: >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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: >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. | |
Re: [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 … | |
Re: [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 … | |
Re: [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 … | |
Re: Why not use Visual C++ Express? It's free. | |
Re: [url]http://www2.research.att.com/~bs/bs_faq2.html#virtual-ctor[/url] | |
Re: >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 … | |
Re: [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. | |
Re: If your project is to implement the code, why do you think stealing it from someone else doesn't constitute cheating? | |
Re: 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. | |
Re: [B]>You know this is written in C not C++... [/B] You know that this compiles as C++ too...oh, apparently not. :icon_rolleyes: | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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. | |
Re: 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 … | |
Re: 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: … | |
Re: [B]>Why is there not a <heap> just as is there is a <set>, etc?[/B] <priority_queue>, perhaps? | |
Re: 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]? | |
Re: [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 … | |
Re: I take it you've already exhausted the tutorials and documentation on the Boost site? | |
Re: 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] | |
Re: 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 … | |
Re: 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"); … | |
Re: What did you try? While it's straightforward, the exact method depends on the result you want. | |
Re: [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 … | |
Re: [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. | |
Re: [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, … | |
Re: [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 … | |
Re: [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 … | |
Re: [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] … | |
Re: Wow, it's a wonder you get that far before crashing. | |
Re: 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. | |
Re: [iCODE]s[/iCODE] is a null pointer. Your code is actually pretty horrible, but the null pointer dereference is your immediate problem. | |
Re: [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 … | |
Re: 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). |
The End.