- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 4
- Posts with Upvotes
- 4
- Upvoting Members
- 4
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
Re: >void main(){ main returns int. Since you can omit the return statement in C++, using int main on top of being correct and portable actually saves you one keystroke. It's a win-win situation. :) | |
Re: >try using %s in the scanf's No, don't. At least don't until you know how to safely use %s and change the input variables to arrays. Otherwise you'll invoke undefined behavior and create security holes/mysterious crashes. >Is there a rule about the use of multiple scanf's? There's one that applies … | |
Re: >Doing a linked list using XOR ... I'm not certain what you mean. It's a hack to avoid wasting extra space on links. It takes advantage of the butterfly effect using XOR. If you take the XOR of two values and XOR it with either value, you get the other … | |
Re: >I would like to know once and for all how to convert a double to a const char* Casting doesn't work. You're not converting the double to a string with a cast, you're telling the compiler to use the binary representation of the double as characters in a string. For … | |
Re: >I'm sure there must be some smart programmers like you who play this game. Only the kids. The rest of us play Everquest. :D >WoW is a monster of a program, is it not? It's probably a monster and a beast. Constant patching, updates, and expansions can wreak havoc with … | |
Re: >I just wanted to change the first character in the sentence to >uppercase, what would I change to do that? Don't call toupper on every character, just on the first one: [code=cplusplus] void printSentence(char *sentPtr){ char *sent = sentPtr; *sent = toupper((unsigned char)*sent); while(*sent) { ++sent; } *sent++ = '.'; … | |
Re: >I wanted to create a MMORPG. That's waaaaaaay beyond you at the moment. Focus on learning C++ as best you can, but don't expect to be able to write an MMORPG anytime soon. You need a lot of foundation knowledge to pull that off, I'm afraid. >For now, is it … | |
Re: >i'm probably doing something basically wrong in the fubction maybe. Are you passing any arguments to your program? If not, argv[1] isn't guaranteed to be there, and if it is, it's pretty much sure to be NULL. If you're passing something, make sure that it's less than 30 characters or … | |
Re: >Do you think life would be better if we had start doing things the it ways years ago. Life is what you make of it. Of course, you should completely define what you mean by "better". :) >How long do you think it could last? About as long as it … | |
Re: >But I heard it's now no longer in use. Managed C++ was the precursor to C++/CLI. It's still in use, but for new code you should be using C++/CLI as it's vastly improved. >C++/CLI could be counted as a new programming >language cause the syntax is similar to C#. C++/CLI … | |
Re: >I know the theory behind it but i dont seem to be able to put it into code! Then you don't really know the theory behind it. ;) Not to be rude or anything, but these are all pretty straightforward concepts and the code ends up being very short compared … | |
Re: >printf(head->data); printf takes a string as the first argument, not an integer. You probably just forgot to add the format string, which would make the line look like this: [code=c] printf("%d\n", head->data); [/code] If you don't mind, I'll make a few unrelated comments: >#include<malloc.h> malloc.h isn't a standard header, and … | |
Re: >wen i use larger values say 245323465 etc. the sorted matrix returned garbage values.. y s that? Garbage values usually mean that you either didn't initialize the value in the first place, or you overflowed it through calculations. I'm guessing that you're seeing overflow errors that should be checked for … | |
Re: I'd start with the fact that functions can't be nested inside of each other in C. You're also calling letter before it's declared. | |
Re: >...Now where do i even begin? You could use everything you've learned in your previous threads that do something similar. >how do i store them so that the other lines are compared to it for the correct answer. Just store it in an array: [code=cplusplus] #include <cstdlib> #include <cstring> #include … | |
Re: If you understood the problem well enough to actually write this program, you wouldn't need to ask what language is best. I'll go out on a limb and say you're in over your head at present. | |
Re: >What about a purely iterative solution, that does not need the excess >memory, and is not logically limited in the number of values to display? That's fine for just printing the sequence. The array is more open to extension though. Let's say you want to write fib(x) where x is … | |
Re: >is dynamic memory allocation really necessaryÉ since you already >know the size of the array which is being passed by the caller Really? How do you know? If you're talking about the length parameter, then yes, dynamic allocation really is necessary because array sizes must be compile-time constants. This isn't … | |
Re: >since its not returning anything? I don't understand. It's [b]clearly[/b] returning something because the code that calls the function uses the return value: [code=c] kptr = function2( n ) ; [/code] You can't use a function like that unless it returns something, and because kptr is declared as a pointer … | |
Re: If it's urgent, won't it be faster to write it yourself than wait for someone to send you something that may or may not work like you want? Also, if it's urgent, it's probably homework, and using someone else's code is cheating. | |
Re: It's better to put the code directly in your post if it's short. The problem is that floating-point values aren't always exact, so you can't reliably test for equality. The usual fix for your problem is to do a "close enough" test using the difference of the two values and … | |
Re: You can use the standard time library to do it, sort of: [code=cplusplus] #include <ctime> #include <iostream> void long_running_operation() { for ( unsigned i = 1; i != 0; i++ ) ; } int main() { std::clock_t start; std::clock_t end; std::cout<<"Beginning timer..."<<std::endl; start = std::clock(); long_running_operation(); end = std::clock(); std::cout<<"The … | |
>I disagree. You have to have all kinds of special code to get scanf() to work properly. Only if you aren't using scanf for what it was designed in the first place. When you have to write workaround code to get a function to work, you're using the wrong tool … | |
Re: >i am currently getting 3 errors They're telling you that you can't use an array as the condition for a switch statement. You can only use integral values (or char, because char is an integral type). | |
Re: If you're using scanf, you can just test the return value. It returns the number of items that were successfully converted: [code=c] int x; if ( scanf ( "%d", &x ) != 1 ) fprintf ( stderr, "Invalid input\n" ); [/code] The format string only has one specifier (%d), so … | |
Re: >.533 microns converted to miles per hour = 3.311908 >.674 microns converted to miles per hour = 4.188042 Well, first, you need to remove the "per hour" part of that. The conversion is strictly distance, not distance over time. Second, you're neglecting to include the exponent in the miles value. … | |
Re: Do you really want to be casting away the precision when you call abs? Maybe you should be using fabs instead so that it gives you the absolute value without losing the precision. | |
Re: >Is it really necessary to write your application in C or C++? It's probably an assignment for a C++ course, so yea, I imagine it's really necessary. Why do you ask? | |
Re: There's no way to print a binary value directly in C. You have to break the value up into bits and basically do it all manually: [code=c] #include <stdio.h> int main ( void ) { int x; printf ( "Enter a number: " ); fflush ( stdout ); if ( … | |
Re: >This program is suppose to add, subtract, and print the complex numbers. It'd be 100% easier if you used the standard complex stuff from the <complex> header. Despite the name, it's actually quite easy. ;) >but im getting some type of error in one of the lines of my code. … |