- Strength to Increase Rep
- +15
- Strength to Decrease Rep
- -3
- Upvotes Received
- 2K
- Posts with Upvotes
- 2K
- Upvoting Members
- 538
- Downvotes Received
- 210
- Posts with Downvotes
- 194
- Downvoting Members
- 48
3,183 Posted Topics
A common task in C or C++ is to get a string from somewhere and convert it to an integer. "Use `atoi`" is a common suggestion from the unwashed masses, and on the surface it works like a charm: #include <stdio.h> #include <stdlib.h> long long square(int value) { return value … | |
Re: > WRONG : Console.WriteLine("%d * %d = %d",c,a,b); Of course it's wrong, WriteLine() does not and never has purported to offer printf() style format specifiers. Saying that the above code is wrong is just like saying that the following line is wrong: Console.WriteLine("FORMAT INT #1 LITERAL(*) INT #2 LITERAL(=) INT … | |
Re: While there might be a tool out there to do the conversion, I wouldn't trust it. The appropriate way is to know both languages and convert manually. However, since assemblies written in either language are interoperable, there's no need to convert unless you're trying to match company standards where only … | |
Re: May I ask why you need to convert that code to C? Seems suspicious. | |
Re: I typically separate testing into two phases: 1. Unit testing for basic functionality and internal correctness that isn't easily checked by the end user or needs to be more thorough at a lower level. 2. UAT testing based on user stories from the design notes. These are cases where there's … | |
Re: Nobody is going to do your homework for you. But I'll give you a push in the right direction. You essentually have two options: 1. Build a new list in sorted order while traversing the old list. 2. Sort the old list into a new list. It's a fairly subtle … | |
Re: Take each number and subtract the mean, then square the result. Finally, divide by the length of the array and add that to your sum. The sum is the variance, and the square root of that is the standard deviation: double sd = 0; for (int i = 0; i … | |
Re: > so those who love banners can enjoy them. Spoken like someone who doesn't depend on ad revenue to stay in business. Hop in chat sometime and ask Dani to explain where Daniweb's funding comes from. She'll talk your ear off, but it's an eye opener. | |
Re: [QUOTE]1) Why I want to delete? I want to delete my account because I've never used Daniweb, so it's useless for me. ... Note that I'm registered since 2009 and rarely (2 times) I came on Daniweb to find answers (sorry but it's the true)[/QUOTE] What's wrong with simply abandoning … | |
Re: > To me, the best type of SEO is popularity. The more popular your site is, the higher ranked you would be (based on backlinks, etc). Indeed. But you're neglecting the critical first step that to become popular you must be noticed. How do you get noticed when your site … | |
Re: This seems more like a job for a frequency list. You can use a dictionary of characters and counts like so: for each word in the dictionary build a frequency list of each character initialized to 0 for each character in the letter collection if the character exists in the … | |
Re: > OKAY YOU NOOBS!!!!! > HERE IS A MUCH SIMPLER THING TO DO!!!! It's also [subtly broken](http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx) if you care about uniform distribution. Simple isn't always better...noob. ;) | |
Re: > Create a TcpClient and connect to the POP3 server, open a NetworkStream that uses the client and download all the data available. You can then parse this using the POP3 specification. That's a gross oversimplification. ;) Doing it right is a non-trivial task, so I'd recommend utilizing a library … | |
Re: While I'd start by suggesting that you use the .NET file stream options instead, String^ *can* be converted to std::string using marshal_as if so needed. | |
Re: The trick with this program is defining what's meant by a "word". You can't just take whatever is separated by whitespace and call it good, because that will incorrectly include punctuation. To properly do it would require some lookahead and lookbehind, and even then poorly formatted sentences could cause an … | |
Re: From the provided code, I can't offer more than int delete_list_entry(temp_head, randvar); should be delete_list_entry(temp_head, randvar); I get the impression there's a little confusion between how to declare/define functions and how to call them. Also, if `delete_list_entry` returns a value, I'd also ask why you're ignoring it. | |
Re: > It could be the Framework or it could be how it has been implemented by my predecessor It's the latter, almost surely. The Entity Framework most certainly has its quirks, but being unstable and slow are not among them when used properly. > So I'm wondering if there is … | |
Re: `p` is a pointer to read-only memory. While some compilers might allow it to be modified, technically what you're doing is undefined behavior. Change line 6 to `char p[] = "foo";` and it should work just fine. | |
Re: > I’ve realized that I’m a little weak when it comes to fix, modify and understand code within large applications, and, needless to say, I need to find a way to get better at it. There are two books I rather like: Code Reading and Code Quality. They go beyond … | |
Re: I'm surprised that nobody has even mentioned the TextFieldParser class in Microsoft.VisualBasic.FileIO... :P | |
Re: What have you done so far? Nobody here will write this for you. | |
Re: I'm a bit surprised you haven't been walking around town handing them out as advertising. There were still a number of big boxes full of shirts after that night, IIRC. ;) | |
Re: > Teaching Pascal as a first language in 2017? Really? Pascal has the benefit of being very easy to understand. It's also hand-holdey, which for most of us translates to "heavily restricted", but for beginners means less working around the quirks of the language and focusing directly on solving the … | |
Re: This is clearly a homework or interview question, so please let us know what your thoughts are first. | |
Re: > Also if the time xomplexity of both the methods is O(n), then how is the second method runs faster than the linear search method? Big O only tells you the expected growth rate of the algorithm, which in both cases is indeed O(n), not its actual execution performance. Algorithms … | |
Re: > This is really confusing as I dont know which is right and which is wrong, could use some help They're both right. Your compiler is right because it's from 1991 and conformed to the C++ of the time. Your book is also right because it's reasonably current with the … | |
Re: > I do not understand why did you make 3 for loops? The real question would be why did the OP not format his code in an understandable way. Reread the original code, it doesn't have three nested loops. | |
Re: > char array's are actually pointers This is a common misconception. An array is *not* a pointer, but when used in value context, the name of an array is converted to a pointer to the first element in the array. In object context, the name of an array is not … | |
Re: > printf("%c occurs %d times in the entered string.\n",c+'a',count[c]); > what is its cout statement cout << (c + 'a') << " occurs " << count[c] << " times in the entered string.\n"; | |
Re: How do you know if a value is a "garbage" value? | |
Re: Most common domain applications, perhaps? Which examples are you referring to? Bucket sort is certainly not limited to that range, though I can imagine how it's wildly useful. | |
Re: Step 1 of troubleshooting is narrowing down the places you need to look. With that in mind, my first question would be whether `dt` actually contains data or not when you look at it in a debug trace. If it does, then binding or refreshing the grid would be my … | |
Re: I'll make the obligatory comment that you should be using a modern compiler rather than trying to kludge a 30 year old compiler into your modern OS. That said, the message suggests this AKKI wrapper is expecting some sort of input. I'd start by reading the documentation to learn how … | |
Re: > ... or use bitwise operator `if(i&1)` if true even else odd. I suppose if you want readers of your code to think you're clever, or have legitimately profiled the code for performance, run all practical test cases, and determined that this micro-optimization is warranted *and* not actively harmful. > … | |
Re: > hey tell me "system()" is in which header file? #include <cstdlib> | |
Re: > The first thing that I would suggest is for you to use some comments stating what everything is and what is is supposed to do and maybe some pre and post condition statements around the class methods. Note that your sample class is a fine example of how *not* … | |
Re: > Can you please explain the reason behind this? You're capturing a direct pointer to the internal storage of the string returned by fun(), which is a temporary object. The temporary object is subsequently deconstructed, and the internal storage goes away. I'd suggest stepping into everything in the debugger to … | |
Re: Well, assuming the title of your thread is the problem, I'd ask what `a.FileName` is and contains. An empty string is indeed not a legal file path, so you want to make sure that `a.FileName` represents a valid file that exists. Most likely there's a flaw in the UI's design … | |
Re: > `while (*p != '\0' || *q != '\0')` This is a red flag. Your arrays are not constructed as C-style strings, so '\0' isn't likely to exist within your owned memory. You can make that happen by adding the terminating value at the end of the arrays: intArray = … | |
Re: > I know that Daniweb owns the I.P. No. That was unfortunate wording in previous terms of service, and the intention was to absolve Daniweb of legal responsibility for storing and editing the content of posts. After a quick reading, it looks like the wording was changed. > I want … | |
Re: I'd strongly recommend walking through your code with a debugger. And my big hint for the problem is that the Enter key places a character in the input stream: '\n'. When you mix formatted and unformatted input (eg. getline and the >> operator), there's a strong chance that newlines are … | |
Re: > I know that the max value for short data type is 32767 Not necessarily. The C++ standard defines a minimum required range, but compilers are free to make it larger. > but the question is from where we get this number -25536 ? First I'll note that it's not … | |
Re: Well, for starters the "/* ... */" comment supports multi-line, so you'll need to consider that in your parsing. A simple approach would be a loop that reads and throws away characters until the closing token is found: public static void processInput(StreamReader input, StreamWriter output) { int ch; while (!input.EndOfStream) … | |
Re: The first thing that comes to mind is to filter out the special value(s): `MyList.Where(x => !double.IsNaN(x)).Min()`. Though depending on what might be acceptable insertions into the list, you might need to consider things like NegativeInfinity as well. | |
Re: The `inline` keyword isn't a guarantee, it's a hint. If the compiler determines that inlining would produce worse code, it doesn't honor the hint. Some compilers just straight up reject the inline hint if there's a loop or troublesome lookup (ie. `switch`). | |
Re: The calculations are unnecessary. `mktime` can be used to normalize the contents of a `tm` structure to the correct date and time after manual modifications. #include <iostream> #include <ctime> using namespace std; int main() { time_t now = time(0); tm *date = localtime(&now); --date->tm_mday; // Move back one day mktime(date); … | |
Re: You could try not running software that's older than most of the people using it... | |
Re: > I have a lot of classes I need to add a ToByteArray() method to What's the purpose of this method? Typically I'd suggest utilizing the serialization classes already present in .NET: public static class BinaryWrapper { public static byte[] Serialize<T>(T obj) { using (var stream = new MemoryStream()) { … |
The End.