3,183 Posted Topics
Re: Sure. You'd wrap the lines in a function and simply call the function when you need those lines to be executed: void show_powerlevel() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3); cout << "Congratulations your power level is now" << PowerLevel << endl; } ... // Use it like this: show_powerlevel(); | |
Re: Once you're connected to a wifi network, the process of using it is the same as a wired network. Have you read [Beej's guide to network programming](http://beej.us/guide/bgnet/output/html/multipage/index.html) yet? | |
Re: How exactly are we talking here, because scanf() is a rather complex function. Ignoring for a moment that there are actually 6 functions in the scanf() family that have a slightly different interface each, the declaration of scanf() itself is like so: int scanf(const char *fmt, ...); The definition will … | |
Re: You create a new list on every iteration of the loop. Move the definition of `ll` outside of the loop and it'll work better. | |
Re: Well, you could use just a 2D array: int marks[3][5]; // 5 marks for 3 students. But that would be less readable, in my opinion, than an array of structures: struct Student { int marks[5]; }; Student students[3]; | |
![]() | Re: Yes, you can use malloc() to allocate a simulated array of int or char. What were you trying to do that prompted this question? ![]() |
Re: Daniweb is not rent-a-coder. If you have a question, ask it. If you only want someone to do your homework for you, please be kind enough to piss off. | |
Re: > dfca2345f1278aba11110012567ade21 How do you plan to differentiate between the 5 separate values (according to your structure) in that line? | |
Re: > If at all there is a differnce between their execution times in the range of nanoseconds or picoseconds? Execution is measured in *"waste of programmer time"* intervals that increase in direct proportion to the triviality of the statement. | |
Re: I think the most common options for choosing a pivot are random and median of three. Ideally you want the pivot to be a perfect median of the current subset being sorted, because that produces an optimal recursive tree. Give [this](http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#quick) a read. It's not perfect, but there's more detail … | |
![]() | Re: "Best" is subjective and dependent on the needs of the situation, but a concise and reasonable generic solution is this one: int count_set_bits(int value) { int n = 0; while (value) { value &= value - 1; ++n; } return n; } The benefit of this algorithm over the more … ![]() |
Re: strtok() is funky in that it works using an internal state through multiple calls. To get the next token you need to call strtok() again with a null first argument (so that it knows to use the previously passed string): output=strtok(input,":"); while(output != NULL) { cout<<output<<endl; output=strtok(NULL,":"); } Oh, and … | |
Re: > The output shows "No error" Probably because there's no error. perror() writes the value of errno in human readable form, along with an optional user provided message. It can literally be implemented like this: /* @description: Maps the error number in errno to an error message. */ void perror(const … | |
Re: How about a lazy update of the cells? It really doesn't matter what the contents of a cell are until you access it for the latest value. Unless the value of a cell depends on all previous cells, you can apply the update as needed rather than en masse, and … | |
Re: What version of Chrome? This might be a stupid question, but did you make sure cookies are enabled? | |
Re: cout << fixed << setprecision(7) << space << endl; Don't forget to include <iomanip>, and take care with expectations when it comes to floating point arithmetic. The results are often approximations and can suffer from accumulated errors. | |
![]() | Re: Undefined objects or functions will be reported at link time. You might also get a warning during compilation, but link time is the hard stop point. |
Re: I'm willing to bet this an encrypted message that students have been given to decrypt as homework. | |
Re: I think you've been here long enough to realize that posting code without any kind of specific question will just piss people off, or at best get you ignored. | |
Re: Here's a hint for asking questions: if reproduction of your problem depends on the content of a file, it's a good idea to post a small part of that content along with your code. This way we aren't forced to imagine what your file looks like and devise test cases … | |
Re: > realloc can do that but STL vector does it support ? std::vector has historically not shrunk memory when the size is reduced to improve the performance of furtuer insertions. The idiom from before C++11 was using the swap() member function: vector<T>(a).swap(a); But with the coming of C++11, std::vector now … | |
Re: > Although I agree that is the proper way to handle something like this, the question says to use nested for-loops. Given that this is the C forum and the link was for a C++ function, I'll go out on a limb and suggest that np complete was recommending that … ![]() | |
Re: > is there any alternative to it? Well, you could read the message and see that strcpy_s() is provided as a "safe" alternative. strcpy_s() is a part of the C11 standard (it's *not* standard at all in C++), but C11 was only ratified in January of this year, so there … | |
Re: Why do you think modifying SubtractMe's copy of sum should affect AddMe's copy of sum? ![]() | |
Re: A segmentation fault is when you try to access memory outside of your address space, or protected memory that you don't own. It's nearly always the result of a bad pointer or array index value, so checking those values should be your first line of attack. | |
Re: It looks okay aside from the class name not being fully qualified in your definitions. They should look like this (notice the template argument is included on the class name): template <class T> T add<T>::sum(T x,T y) { a=x;b=y; return a+b; } template <class T> void add<T>::displaysum() { cout<<endl<<"sum is … | |
Re: Video uploads seem emminently impractical to me. On top of the size issue (even small videos are relatively gigantic), and latency of retrieving the files, there's also the problem of playback for various formats. If we implemented something even remotely like this, at the very most it would be tags … | |
Re: That's what you get when you lie to scanf(). Assuming 4 byte integers, `a` looks like this (the question marks mean an indeterminate value): [?][?][?][?] Now when you pass the address of `a` into scanf() and say that it's a pointer to char, scanf() will do exactly what you asked … | |
Re: Since you've sidestepped the command shell's conveniencies like being able to edit your input before sending it to the program, that functionality needs to be duplicated *within* your program. In this case that means recognizing and handling the any special characters that the shell normally handles for you: #include <stdio.h> … | |
Re: It's a very straightforward usage of function pointers. Here's a quikie example using a stack: #include <stdio.h> #include <stddef.h> #define CALLBACK_MAX 10 typedef void (*callback_t)(void); static callback_t callbacks[CALLBACK_MAX]; static size_t n = 0; void register_callback(callback_t callback) { if (n == CALLBACK_MAX) return; callbacks[n++] = callback; } void run_callbacks(void) { while … | |
Re: > but result in console is not same as txt file The line break after each number in your file is a character too. scanf() first reads 'A' and 7 correctly, then prints them. Next it reads '\n' as the character part, but fails the integer part because 'c' isn't … | |
Re: > time_t is the number of seconds since 1 Jan 1970 to the specified date. While it is indeed the canonical epoch, there's no guarantee that time_t represent the number of seconds since 1/1/1970. For example, I very seriously considered using 1/1/1900 as the epoch for my time.h library, to … | |
![]() | Re: [Beej's Guide](http://beej.us/guide/bgnet/) is pretty much all you'll need. |
Re: > hii decptikon if ur der please give me a solution I require that you make an attempt first. The problem statement is also ambiguous. Are you reversing the bits in each nibble or swapping the nibbles? Anyway, without actually solving the problem for you, I can help you visualize … ![]() | |
Re: Try calling the sin() and cos() functions from the cmath header. | |
Re: > What does the tree look like? Why should that matter? As long as it's a valid binary search tree, the algorithm won't change depending on how the tree looks. > Can anybody share the algorythm to perform inorder traversal of a binary search tree using parent node(without stack or … | |
Re: Members of a structure may be aligned to certain byte boundaries to improve performance or if the platform simply doesn't allow an object of a certain type to begin at any byte. Also, and partially to facilitate alignment, there may be padding between members of a structure or at the … ![]() | |
Re: > asrockw7 Thanks man. but your adivise for proffissnal not bigiiner like me ^^ Um, no? Breaking a problem down into manageable pieces and experimenting with ideas in a small and controlled environment is programming 101. It's something every beginner should be learning on their first day, and a skill … | |
Re: Take a look at the ctime header. It includes types and functions for manipulating dates and times. With minimal effort you can parse your time string into a tm structure, convert those into time_t objects with mktime(), and finally get the difference with difftime(). | |
Re: > I'm curious how these two approches actually test for valid values. At least for strtod(), a combination of the return value and end pointer as the second argument can be used to validate the string. If conversion stopped before the end of the string, then it's not valid. I'm … | |
Re: It would be helpful to know what input you're passing in so that we can duplicate your test case. ![]() | |
Re: There's already an optional comment for votes that also applies reputation points. When you click on either an up or down arrow, the comment box will pop up. | |
Re: > Yes, but it's not built in to the language or standard libraries. Actually, it is as of C11. Though the trick with the latest standard is finding an implementation of it. Hopefully C11 will be more widely adopted than C99. ;) | |
Re: Oddly enough, I think I'm in favor of option 2. Though there would definitely need to be a way to hide excess numbers of comments. It's rare currently, but if the reputation system is used more often because of this feature, that kind of thing might become more common. | |
![]() | Re: Our permission/ranking system isn't strictly by post count. Specifically, the difference here is between a Newbie Poster and a Community Member. Once you've reached the threshold of either 15 reputation points or 5 posts plus 5 days since joining, your rank will automatically go from Newbie Member to Community Member. … ![]() |
The End.