3,183 Posted Topics
Re: You're not doing anything wrong. Windows Forms is notorious for having a noticeably slow redraw out of the box. There are a number of ways to improve matters, but the list is kind of long, so I'll just suggest searching google. One thing to keep in mind is that C# … | |
Re: It's the preprocessor's pastie operator. It takes two tokens and concatenates them into a single token. For example: [code] #include <stdio.h> #define PASTIE(prefix, var) prefix ## var int main(void) { char const* strFoo = "foo!"; puts(PASTIE(str, Foo)); return 0; } [/code] Neither str nor Foo are meaningful by themselves, but … | |
Re: Structurally the program makes no sense. main() is embedded inside circle, and circle isn't properly terminated. name is a variable local to main() but it's being used as a member of circle. This compiles, but I didn't run it: [code] #include <iostream> #include <iomanip> #include <cmath> using namespace std; struct … | |
Re: If the seed is always the same, the pseudorandom sequence will always be the same. Change the seed to something other than 8, and A will probably be different. | |
Re: Where is your avatars folder relative to the root folder? If the file is there, it sounds like the problem is as simple as getting the path correct in your img tag. | |
Re: [QUOTE]I'm pretty much all lost/braindead on step 6. [/QUOTE] It's a variation of the algorithm for checking if an array is sorted. If it's not sorted in ascending or descending order, the profits fluctuated, which is pretty easy to check: [code] #include <iostream> #include <string> using namespace std; string ProfitTrend(int … | |
Re: Your printword() function is making the results look different from the paper. Try this instead: [code] void printword(WORD A) { printf("%08X ", A); } [/code] | |
Re: The code continually allocates new memory to ptr, which leaks away the previous memory and loses any previously assigned numbers. Rather than outline all of the possible cases and explain why they're necessary, I'll just give you a function to study: [code] bool ResizeArray(int*& a, unsigned old_size = 0, unsigned … | |
Re: I can't reproduce your problem, it encrypts the whole sentence for me. What compiler and OS are you using? | |
Re: You can get details about what happened after fopen() failure like this: [code] FILE* tmpfile = fopen(xxxxxx, "r"); if (!tmpfile) { perror("Error opening file"); } [/code] | |
Re: Uninitialized pointers are not pointers to infinite memory. You have to allocate memory before trying to write to it: [code] #include <stdio.h> #include <stdlib.h> int main(void) { struct Person { char *firstName; char *lastName; }; struct Person newPerson; newPerson.firstName = malloc(50); newPerson.lastName = malloc(50); printf("Enter your first name and last … | |
Re: Yes, there are more corrections. How many more depends on the compiler you're using, because this code makes assumptions about the language that aren't supported by modern compilers. But if you ignore those problems, there are four corrections required to make the code compilable. You have options in what corrections … | |
Re: [QUOTE=gourav1;1763824]damn awsome links. simply saying "superb info". and i am still not getting my second question....."second question is that : when i don't give "\n" with the statement(number 12) (scanf("%d\n",&t), then it skip the gets() statement in the while loop , but when i give "\n" then it works properly..please … | |
Re: [QUOTE]I am stuck in how does cin.clear() and cin.ignore(200, '\n') work[/QUOTE] cin.clear() resets the error state of the cin object. So if any of cin.eof(), cin.fail(), or cin.bad() return true, they'll return false after calling cin.clear(). The reason you need to call cin.clear() is because until the error state is … | |
Re: [URL="http://onecore.net/creating-standalone-graphics-programs.htm"]This[/URL] seems relevant. | |
Re: So...what's the problem, exactly? | |
Re: When you say you "can't use arrays", what exactly does that mean? Because it's quite impossible to sort anything when you can't retain it, and while you can use 25 variables to get the same effect as an array, that's totally insane. I can't imagine a teacher expecting you to … | |
Re: It's certainly a suggestion worth looking into. | |
Re: The error says it all: regular functions cannot be nested in C++. Move your definition of selectionSort() outside of main() and call it in case 7 instead. | |
Re: There's no difference at all. The array notation for a function parameter is just syntactic sugar. Internally it's treated as a pointer, and you can use it as a pointer, which does indeed include pointer arithmetic: [code] #include <stdio.h> void traverse(int a[], int n) { while (--n >= 0) { … | |
Re: If you need that kind of control over the user experience, I'd say write a GUI-based program instead of a console program. | |
Re: Where do you give $banners_result a value? | |
Re: [URL="http://beej.us/guide/bgnet/"]Beej's guide[/URL] has been the recommended first stop for many years. I'd recommend purchasing the book for offline reading too, 'tis worth it even though the book is rather thin. :) | |
Re: [QUOTE]is there is any other language which is safe from decompiling[/QUOTE] Better question: Why are you worried about decompiling? | |
Re: Language lawyers can argue a few reasons why that would fail, but in practice it's all but guaranteed to work. | |
Re: [QUOTE]Is a=b+c+d considered as one instruction or 2 instructions?[/QUOTE] Neither. Barring compiler optimizations, there are three operations going: two additions and an assignment. As far as instructions go, a naive interpretation would be: [CODE]mov r1, b mov r2, c add mov r2, d ; Assuming add puts the result in … | |
Re: The simplest solution would be to make subsequent queries into your table for the make, excluding the id that you're already displaying, and order the results by price. Then you can insert those into your expanded rows display. Alternatively, depending on the size of the table, cost of database queries, … ![]() | |
Re: [QUOTE]the title says it all[/QUOTE] If by "says it all" you mean that it says one can ignore your thread due to lack of information, I'd agree. :D Since I know jack squat about CDF, I'll just try to answer what I think is your question. [QUOTE]What I know is … | |
Re: [QUOTE]Is there a point writing my own heap for time optimization?[/QUOTE] It's pretty unlikely that an ad hoc heap would be faster than std::priority_queue. Not to mention the effort of reinventing the wheel *and* the huge risk of bugs in your implementation that just aren't there with an existing oft … | |
Re: It's also probably not a good idea to clear the screen after every iteration of the loop without some kind of pause involved. The program will run too quickly to see the changes and will look like it's just printing a single random number. | |
Re: The problem is not with fgets() reading a newline character, it's with scanf() leaving a newline character in the stream for fgets() to read. To fix the problem, change how you're using scanf(), or use a different method of input. There are two common recommendations. First, you can avoid scanf() … | |
Re: [QUOTE=Esmerelda;1748323]ok..then c=++a + ++a + ++a should give the output c=24 but its c=22. ???[/QUOTE] Undefined behavior is the Schrödinger's cat of programming. The result of an undefined expression could be anything until you actually run it, and the result you get in practice depends on too many factors to … | |
Re: This game is an amusing diversion. Like Ali 2101 said, kbhit() is the easiest way to check for a key press in compilers that support it. You can also fake kbhit() with the Win32 API, but that's not necessary in this case. Here's a sample game that does something similar: … | |
Re: Your question is ambiguous. Please provide an example with input and the desired result. | |
Re: strcmp returns the difference of the two strings. If the first string is "less" than the second string it returns a value less than 0. If the first string is "greater" than the second string it returns a value greater than 0. And if the two strings are identical, it … | |
Re: p is a pointer to char, not int. So when you increment by 1, it increments by 1 byte instead of the number of bytes in an int. I think you should throw that book away if that program is a sample of its quality. | |
Re: None of those are standard C++ functions. What library are you using to get them, or what compiler are you using if they're extended library functions? | |
Re: [QUOTE]Every time I run my program, and enter a character, my program prints the correct output (for example if I enter 'n' the first time, my program outputs "you've deposited 5 cents"), but then it also outputs the default message every time ("Whoops you've entered the wrong command, please try … | |
Re: One example: You may want the lifetime of the object to not be restricted to the scope in which it was declared. Dynamic memory has a lifetime of when you allocate it to when you release it. | |
Re: Be aware that 2 digit dates *will* cause overlap between the 1900s and the 2000s, but if you have a hard lower bound on the 1900s, like 1970, you can check for that explicitly and be good until the same year in the 2000s: [code] // Works until 2070 if … | |
Re: std::vector and std::string do a lot of work internally. You'd probably be better off converting the 'what' instead of the 'how'. Ask yourself what the code is trying to accomplish and write C code to do it. | |
Re: age is never set to anything other than 0. What you probably wanted was something more like this: [code] int age; Console.Write("Please enter your age: "); if (int.TryParse(Console.ReadLine(), out age)) { if (age >= 65) { Console.WriteLine("You are entitled to discount"); Console.ReadKey(true); } else { Console.WriteLine("You are not entitled to … | |
Re: It's not possible without writing your own preprocessor that adds appropriate escape characters for the stringizing operator. | |
Re: I'd say continue where you left off, and review previous chapters as necessary. | |
Re: You're probably using cin like [ICODE]cin >> s[/ICODE]. That method stops reading at whitespace, so s is only populated with the first word from input. If that's the case then it has nothing to do with how the code copies to the clipboard, and you can fix it by reading … | |
Re: [QUOTE][CODE]scanf("%d", &hourlyRate);[/CODE][/QUOTE] %d is for integer input. For double input use %lf. [QUOTE][CODE]printf( "Miles gallons was %d\n\n", salary );[/CODE][/QUOTE] Just like scanf(), printf() expects you to tell the truth about what type of variable is being printed. salary is a double, but %d says that it's an int. That technically … | |
Re: Perhaps consider something more like this: [code] string GridToXml(DataGridView source, string root, string element) { var doc = new XmlDocument(); doc.LoadXml("<" + root + " />"); foreach (var row in source.Rows) { var element = doc.CreateElement(element); foreach (var cell in row.Cells) { element.AppendChild(doc.CreateElement(cell.OwningColumn.HeaderText)); element.LastChild.InnerText = cell.FormattedValue; } doc.Firstchild.AppendChild(element); } return … | |
Re: [QUOTE]I have been trying to take input until empty string is entered(simply press enter) ?[/QUOTE] The >> operator doesn't recognize whitespace except as a delimiter on both sides. If you just press enter, it's ignored while the >> operator waits for non-whitespace. To check for a blank line you would … |
The End.