6,741 Posted Topics
Re: >So please help Try searching for WinMain on [url]www.google.com[/url]. Seriously, it's not that hard to do a little bit of research and come up with [i]something[/i]. We tend not to take kindly to willfully clueless people. | |
Re: The char type is an integer type, but when you use the << operator to print it, it's assumed that you want to print the character representation. To get the numeric value you can cast to an integer: [code=cplusplus] #include <iostream> int main() { const char *s = "test"; for … | |
Re: [B]>cout << dist[1][1] << endl; // This correctly displays 0 (not initiallized yet)[/B] Which means either you got extremely lucky, your snippet is misleading and dist has static storage duration, or you're relying on a compiler extension that automagically fills arrays with 0. The following would be more correct: [code=cplusplus] … | |
Re: >I mean can I do these kind of stuff just using C programs Yes. >can C language be used as a code of virus Yes. >if yes how By typing code into a text editor and then compiling it to an executable file, just like any other program. | |
Re: >What is the difference between programming and scripting? Scripting is generally thought of as application extension that cannot run without the aid of a hosting application. Shell scripts, for example, can't run without the aid of the shell, but they're not a component of the shell. Programming on the other … | |
Re: Oddly enough, most of the problems with stream input are solved the same way: read an entire line into a string and then parse that line for validity: [code=cplusplus] #include <iostream> #include <sstream> #include <string> int main() { std::string line; std::cout<<"> "; if ( getline ( std::cin, line ) ) … | |
Re: >help me out! Ask a specific question, and then say "please". We're not slaves you can order around. :icon_rolleyes: | |
Re: [QUOTE=tux4life;872874]You forgot to add the line [ICODE]Input.open();[/ICODE], same applies to Output :)[/QUOTE] The constructor does this for you if you provide a file name. [QUOTE=tux4life;873190]Try [ICODE]ifstream Input("Input.txt", ifstream::in);[/ICODE] instead of [ICODE]ifstream Input("Input.txt");[/ICODE] :)[/QUOTE] Both of those are equivalent. I would be both shocked and dismayed if there were a difference. | |
Re: Since nobody bothered to show you how to get a random floating-point value, here's a complete program to help you out: [code=c] #include <stdio.h> #include <stdlib.h> #include <time.h> int main ( void ) { int i; srand ( (unsigned)time ( NULL ) ); for ( i = 0; i < … | |
Re: The problem you're asking about is [ICODE](text - '0')[/ICODE], which doesn't work because text is a string and not a character. You probably meant [ICODE](text[i] - '0')[/ICODE]. However, that's not going to be of much help because the rest of your program is horribly broken. Here are some examples: >string … | |
Re: >If you will give me permission, I will send my pseudocode to you in a private message. It doesn't work that way. This isn't a private mailing list, it's a public forum. >This will prevent cheating from other students. No, it won't. All the cheaters have to do is pretend … | |
Re: Split to a new thread. >how i can convert string to int in c++ gui mode "GUI mode" is irrelevant. The process is the same. Have you tried a stringstream? [code=cplusplus] #include <iostream> #include <sstream> #include <string> int main() { std::istringstream in ( "10" ); int i; in>> i; std::cout<< … | |
Re: >given a function, how do you tell the size of the array that is passed? Given a function where the only parameter is a pointer to the first element of said array, you don't. There's no portable method, which is why the usual advice is a second parameter with the … | |
Re: [quote=tux4life] >Do you know what happens if atoi fails to convert? Then a zero value is returned, or am I wrong? [/quote] atoi either returns 0 or invokes undefined behavior. But you can't stop the undefined behavior without carefully validating the string before calling atoi. You also can't tell if … | |
Re: >Is there a way to convert from const char * >to char * without casting away the const? Short answer: No. >I was warned that it could be dangerous and cause crashes It's const for a reason. For example, when you point to a string literal, the pointer should be … | |
Re: >i have tried it in visual studio 2003 From the OP's use of <unistd.h>, which strongly suggests that he's on a POSIX system such as Linux or Unix, I don't think suggesting a C++/CLI solution (a language currently unique to Windows and .NET) is such a hot idea. | |
Re: I would recommend creating it as a data member of the parent form class and then passing it around as necessary. Globals are tricky to get right. | |
Re: >Yes, but apply the same rule to 15000, 1500, 150 and 15, what now? It works fine? As long as you have the right special cases for identifying a teen and ignoring zeros, all is well with _Nestor's logic. | |
Re: Due to the implied illegal nature of the request, I'm closing this thread. Creative!on, do not ask how to acquire cracked/pirated software again or you'll be in violation of Daniweb's rules. When it comes to Keep It Legal, we do reserve the right to contact the proper authorities, which should … | |
Re: >it always reminds me that i am a foreigner and causes some sort of alienation. But you [I]are[/I] a foreigner. No amount of pretending otherwise will change that, and it's kind of insulting to your country of origin (not to mention your family). Also keep in mind that even if … | |
Re: Strange values usually means you didn't initialize a variable somewhere. For example, you don't initialize total2 when it should be set to 0 for an accurate sum. | |
Re: Often the line that's given in the error is where the error finally breaks compilation. The actual problem is more likely to be up a few lines. >I'm programming in vs6.0, if it is important.. It's important enough for me to tell you that Visual Studio 6 is one of … | |
Re: [B]>-How did this type of work interest you and how did you get started?[/B] I think I'm well suited to my job, and it interests me greatly. As for how I got started, I did it to win a bet. [B]>-How did you get your job? What jobs and experiences … | |
Re: >I have uploaded them to a word file because i thought posting >those questions here would make this place clumsy.. We're lazy. If we have to download an attachment or (horrors!) go to rapidshare, we'll just pass your thread by and answer another one. Unless there are hundreds of questions, … | |
Re: [psychic debugging] You probably forgot to terminate your class definition with a semicolon and the constructor definition immediately follows it. The following code should produce a similar error: [code=cplusplus] class foo { public: foo(); } foo::foo() {} [/code] The error is saying that the constructor for foo is trying to … | |
Re: Why exactly is the environment rewriting your defines to be something different? That kind of defeats the purpose of manifest constants. | |
Re: >I have no idea what the error means Neither do I, you only gave us part of it. | |
Re: You clearly know enough about sorting to mention one of the common (unfortunately) algorithms by name: bubble sort. I get the impression that you haven't even attempted to write the sort, so I'll simply link you to [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#bubble"]a tutorial[/URL]. | |
Re: If you're seeing a runtime error inside free, it means you corrupted the memory. Verify that you're allocating enough memory, then make sure you don't access that memory out of bounds. There's nothing wrong with the free function itself. | |
Re: >do a check to see if the variables exist in my main program Just how do you plan on doing that? Are you also parsing the code of the main program? If not, do try to remember that variable names are lost during compilation. The big problems is that variable … | |
Re: >im getting tons of errors, any suggestion on where to start? If you're getting tons of errors, then that means you cranked out code all in one sitting without compiling or testing. That's the express train to crappycodeville. Write a little, test it, write a little, test it. Not only … | |
Re: >undefined reference to `rand_1toN(int)' rand_1toN isn't going to magically do something. You have to give it a definition. | |
Re: >I should either live with it or use a compiler that supports "export"? If the question is whether you should use [ICODE]export[/ICODE] or live with keeping template class definitions with the declarations, you should just live with it. [ICODE]export[/ICODE] is...problematic. You'd be better off not using it until everybody has … | |
Re: >it doesnt create a.dat Are you looking in the right place? >also how would i switch f from read state to write state? Flush or seek, and you're good to go. | |
| |
Re: >And the last question, how do you force an exit out of several loops? Ideally you would refactor the "several loops" into a function. Then to force an exit you simply return. | |
Re: >Is there any problem when i compare the two strings ? You're not comparing strings, you're comparing pointers to char. What you need to do (assuming you can't switch to the std::string class) is compare using [URL="http://www.cplusplus.com/reference/clibrary/cstring/strcmp/"]strcmp[/URL]. | |
![]() | Re: >The elements I can think of would be strength, weapon, accuracy and skill. I would split those up. Instead of lumping accuracy and skill into an attack, accuracy and skill would apply to a chance-to-hit calculation that gives you a percentage. If your random roll falls within that percentage, then … |
Re: >because they are treated like a function instead like cout and cin >being treated as a object thus equaling faster code generation Code generation differs between compilers. scanf and printf may be faster on the "very good programmer who is both fluent in c and c++"'s compiler, but the opposite … | |
Re: >My example does probably what the OP requires in simpler terms. Not really, seeing as how the OP was specifically asking for the usage of std::find in the case of composite data, not a replacement for std::find that does the same thing. | |
Re: [code=cplusplus] std::string path = "path\\to\\desktop"; [/code] Don't forget to include the <string> header. | |
Re: >how can i convert a hex value of a byte (unsigned char) to a short value? By assigning it, perhaps? :icon_rolleyes: [code=cplusplus] unsigned char hexByte = 0x02; short value = hexByte; [/code] Your question betrays a misunderstanding of how numbers are represented in memory. There's no conversion going on[1]. The … | |
Re: [psychic debugging] [url=http://www.daniweb.com/forums/thread90228.html]This[/url] describes your problem and shows ways to get around it without changing your input logic. [/psychic debugging] | |
Re: >(*hPtr).style = "abc"; You don't copy arrays like this. You also don't compare arrays with the relational operators either. Further, at this point hPtr doesn't point to anything. You need to point it to an address that you own: [code=c] #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { struct … | |
Re: >I am unable to understand How and where will such a pointer be useful? I assume you mean a pointer to a function in general. One example is in the C standard library: [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/"]qsort[/URL]. Without using a pointer to a function as a callback, there wouldn't be a good way … | |
Re: If by "help" you mean "do it for me", you can kindly piss off. If by "help" you mean "help", we'd be glad to, but your post is lacking in the necessary information to provide said help. | |
Re: >Who knows, the judges may even give you the first prize. A magnificent F certificate. Ooh, I want in on that: [code=c] #include <stdio.h> #include <string.h> int main ( void ) { char buf[BUFSIZ]; if ( fgets ( buf, sizeof buf, stdin ) != NULL ) { main(); buf[strcspn ( … | |
Re: If you have an actual array, you can use the sizeof trick regardless of the type of the array: [code=cplusplus] int Rows = sizeof arrString / sizeof *arrString; [/code] This divides the size of the array in bytes by the size of the first element of the array in bytes. … | |
Re: >When you call malloc, it gives you a pointer to the dynamically allocated memory. That's correct! Congratulations. >The first few bytes show how much memory is being allocated >so that "free" knows how much space to release. Bzzt! Wrong. There's nothing stopping implementations from storing the size elsewhere, such as … |
The End.