6,741 Posted Topics
Re: Closes? I'd more expect it to hang since the first loop of the combination calculator is infinite. Though it's quite likely the undefined behavior of overflowing your data types causes a crash. Can you describe what happens when the program "closes"? | |
Re: How about two wrappers with implicit conversions? [code] class Radian { double value; public: Radian ( double init ): value ( init ) {} operator double() { return value; } }; class Degree { double value; public: Degree ( double init ): value ( init ) {} operator double() { … | |
Re: [B]>what is the reason that int, float,char,double, >bool are of 4,4,1,8,1 byte respectively in C++?[/B] Perhaps if you explain why you think those values are wrong, we can offer enlightenment. [B]>are arrays built in?[/B] Do you need to include a header? No? They might just be "built in" then. [B]>128 … | |
Re: At the risk of confusing you, I'll offer a more robust solution than you'd normally be given. Since it's more complex, I'll happily explain anything you don't understand: [code] #include <stdio.h> #include <string.h> int continue_working ( const char *msg, const char *true_case ) { char buffer[BUFSIZ]; /* Don't do printf(msg); … | |
Re: [B]>what they do have is an unsigned char class to >convert ints/doubles/floats to binary/bytes.[/B] You're thinking of type punning, I believe. Tricky business that stuff, not usually a good idea in C++. [B]>if you have an unsigned char*, you can't actually get >the size of the number of bytes this … | |
Re: [B]>how to find the no. of characters which are in a file in c program[/B] Open the file and count them. Though I suspect you're asking the wrong question. Most of the time this question comes up when somebody wants to allocate a buffer large enough to hold the entire … | |
Re: [B]>can someone help me get the codes for this program..[/B] I'm sure somebody hates you enough to stunt your growth by giving you code. The whole point of assignments like this is to make you practice solving problems and translating those solutions into code. So try it yourself first, then … | |
Re: I'm not sure I understand what you're asking. It sounds a bit like you want to create an abstract data type but don't know how. If that's the case, you can check out the libraries offered [URL="http://www.eternallyconfuzzled.com/jsw_home.aspx"]here[/URL] for one such method. The data structures are a bit more complex than … | |
Re: String literals use double quotes, character literals use single quotes. My guess is that you need to come to terms with the fact that [ICODE]char[/ICODE] is not a string type, then look at the std::string class. | |
Re: [B]>Yea, looking at your code makes my brain hurt.[/B] If you're not exaggerating then you should probably do something about that weak mind. Maybe take up sudoku. ;) | |
Re: strcat expects a valid C-style string (ie. an array of char terminated by '\0'). In your case, you failed to meet the requirement that the array is terminated by '\0', so you've invoked undefined behavior. This should help: [code] char *cdisp; cdisp = new char[200]; // Add the following line … | |
Re: [B]>this might b helpfut for you[/B] Perhaps if your program is the only one running on the machine. A busy loop like the one in your [ICODE]wait[/ICODE] function is a terrible CPU hog. Seeing as how the OP's program really only does two trivial things once per second (print the … | |
Re: [B]>is cyclic hashing possible??[/B] Yes, though as described it looks like you're trying to independently invent [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_hashtable.aspx#openaddr"]linear probing[/URL]. | |
Re: >Pls help me in finding hcf and lcm of 2 nos It's easy. All you do is grab the igm, do a qp on the xt half of the pgid and roll everything up into a qt7-qualified czsm. Hope that helps! :) | |
Re: [url=http://eternallyconfuzzled.com/jsw_home.aspx]This[/url] covers several different trees, including a variation of the heap. I haven't yet gotten around to finishing my splay tree tutorial, but here's a draft of the code (for both top down and bottom up splaying): [code=c] #include <stdio.h> #include <stdlib.h> #include <time.h> struct jsw_node { int data; struct … | |
Re: >I/O ops defined in STD namespace .... I/O manipulators are deined in iomanip They're all in the std namespace. The streams and manipulators without arguments are declared in iostream, manipulators that take arguments are declared in iomanip. So to use setw and the like, you need to include iomanip, but … | |
Re: [B]>I doubt it'll stem the flow of begging or spoonfeeding - which >is becoming a growing problem - but it wouldn't hurt.[/B] IMO, all of those announcements and stickies are completely ineffective for fixing the problem. All they do is make it easier for mods to justify punitive action. | |
Re: >Is it possible to create your own data type? Not a class, or a >structure, that builds from predefined C++ types, but your very own. What do you think a class is supposed to be? It's a user-defined type. What you seem to want is magic: a magic type that … | |
Re: Every C++ test I've seen online has been lame. You'd be better off asking us for tough questions and collecting them into your own test. | |
Re: [B]>Is it true that the finally block doesn´t execute either ?[/B] The finally block always executes, whether an exception was thrown or not. | |
Re: [B]>Is this correct?[/B] Give it a try, the code to test this function is trivial. | |
Re: [B]>I see the "new" operator is very different from java one, is it right?[/B] Not especially. The Java new expression creates an object of the specified type, calls the specified constructor, and returns a reference to the object. This is pretty much identical to C++ where a new expression creates … | |
Re: strcpy is for C-style strings, not C++ string objects. >How to solve it?? Change that line to this: [code=cplusplus] t_time = hr_str; [/code] | |
Re: >// I think there should be a return but my compiler doesn't give me an error Just because your compiler doesn't complain doesn't mean that there's no error. | |
Re: [B]>I can reconsider my personal opinion on the big G policy if they will close to >Chinese government request also if this mean close the business in China.[/B] You should send them an email. I'm sure that changing your personal opinion is a huge incentive for Google. | |
Re: [B]>I still don't understand why I need to use namespace[/B] Because the standard library places everything in the std namespace. If you want to use the standard library, you have no choice but to at least mention that namespace somewhere in your code. [B]>What happens if I don't use it?[/B] … | |
Re: [B]>when i ran this program, it said that it was unable to open the file.[/B] The file probably isn't where ifstream is looking. Try calling perror to see if it gives you more information. | |
Re: [B]>a constructor for a class is only used to initialize variables[/B] What about a shared resource manager that puts a lock on the resource in the constructor and unlocks it in the destructor? The constructor may or may not initialize data members, but also does other work. | |
Re: [B]>But what is the difference here?[/B] [ICODE](&FileParser::saveElement)[/ICODE] is parsed as the address of a class member. The parentheses are redundant in this case. [ICODE]&(FileParser::saveElement)[/ICODE] is parsed as trying to access a static member and then take the address of it. [ICODE]saveElement[/ICODE] isn't a static member, and if it were a … | |
Re: Did you try putting the text file in the same place as the exe on your desktop? | |
Re: [B]>It works the problem is I would like to ensure I'm meeting the professors intent.[/B] I can't claim to know what your professor intended, but I'd say you're on the right track. | |
Re: [B]>In standard C++ you can't. If your compiler is one of those that has enhancements, >there may be a way, but it's non-standard and therefore not recommended.[/B] I can only assume you were running on autopilot and didn't proofread your post, because that's just stupid. If there's a standard alternative, … | |
Re: [B]>I am trying to find the best cmplier for the C++ program.[/B] If one compiler were the best, there wouldn't be so many out there, would there? :icon_rolleyes: The trick is to try out a bunch of them and pick the one you like best. | |
Re: [B]>I got them for free how much are they worth?[/B] Did you check ebay? | |
Re: [B]>Can anyone tell me why?[/B] Your pointer is uninitialized. It's not a pointer to infinite memory, it's an [i]invalid[/i] pointer. Expect crashes and unpredictable results, because that's what happens with undefined behavior. [B]>I wanted to take a line input of infinite length.[/B] It's not that easy. You need to read … | |
Re: >How does compiler impliments intializer lits? It depends on the compiler. >How intializer lits improve performence? There are two steps when you initialize in the body of a constructor. The first step is performed before the body, where the data members are allocated memory and given a default value. The … | |
Re: [B]>i tried a somewhat natural approach, which seems to have failed..[/B] Completely understandable. However, the rule that an array name becomes a pointer to the first element only applies to the first dimension. So your function should be declared as one of the following: [code] // Pointer to an array … | |
Re: [B]>'isnum' : cannot convert parameter 1 from 'float' to 'const char *'[/B] Why yes, a float is indeed not the same as a string. You can take input as a string rather than a float to correct the problem. Alternatively you can convert the float to a string, in which … | |
Re: [B]>Can you help me please ?[/B] Not until you show us your attempt and prove that you're not a cheating leech. | |
Re: [ICODE]w[/ICODE] and [ICODE]w->word[/ICODE] are two separate pointers that (as you say) were allocated using two separate calls to the memory manager. Therefore, the code you posted is correct. Make sure you don't call [ICODE]free(w->word)[/ICODE] in a loop, or in two different places. | |
Re: I get the impression that you're looking for a variant type. C isn't good at that, so you might consider something more along these lines: [code] #include <stdio.h> #define TYPEA 0 #define TYPEB 1 struct my_struct { int type; void *data; }; struct a { double x; }; struct b … | |
Re: LPCWSTR is a wide string type, but std::string is a narrow string type. You need to decide which one you really want to use and either switch to std::wstring, or turn off Unicode for your application so that the Win32 functions don't use the wide versions. | |
Re: [B]>how does the ramdomize function works?? >does it have some formulae to bring out its output?[/B] [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx"]This random number tutorial[/URL] might help. [B]>Computers can't generate random numbers the way our mind does[/B] Our minds are exceptionally bad at coming up with random numbers. If you grab anyone off of the … | |
Re: [B]>Or loop through the 'char' and use the num = (num * 10) + char process.[/B] Nine times out of ten, this algorithm breaks on edge cases. Unless it's a homework problem, such a manual process isn't recommended when there are better alternatives like std::stringstream. [B]>Use something like this[/B] Manually … | |
Re: Hmm, I think [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_bst1.aspx"]this[/URL] might be a good read for you. | |
Re: [B]>2) when the person enters his password it should not be visible.[/B] You need a way of reading raw input without echo. The most well known function that does this is getch, from <conio.h>, but I can't recommend that because I don't know what compiler you're using. You can search … | |
Re: [B]>How to make a time based regular function? >Like something that plays a sound every 1 second?[/B] To what end? If all you want to do is hog the process and play a sound every second, it's a trivial matter: [code] #include <iostream> #include <windows.h> void kindadumb() { for ( … | |
Re: [B]>Q[/B] Really? I'm surprised you took the time to hold down the shift key if you were too lazy to come up with any kind of useful title. [B]>I wanna ask about virtual function.. why we use it & when?[/B] You make a member function virtual when you want to … | |
Re: This is where you write a test program to find out for yourself: [code] #include <stdio.h> int main ( void ) { const char *s = "test"; const char *t = "temp"; do printf ( "s: %c\tt: %c\n", *s, *t ); while ( *s++ == *t++ ); return 0; } … | |
Re: [B]>Am am I right in thinking it has something to do with external linkage?[/B] Something like that. The following operators are implicitly declared in every file: [code] void *operator new ( size_t bytes ); void *operator new[] ( size_t bytes ); void operator delete ( void* ); void operator delete[] … |
The End.