2,384 Posted Topics
Re: Are you using a debugger? Can you add a few lines of your own code such as [code]if ( Ypix < 0 ) { puts("whoa!"); /* put breakpoint here */ }[/code] Maybe even sprinkle more than one of these around the loops to try to narrow down the search? | |
Re: Read the user input as a string, validate the string according to the specific details for dollar amount entry. Such as, begins with dollar sign, is followed by nothing but digits until a possible decimal point, and then no more than two digits. Or whatever. | |
![]() | Re: Seems more like C++. Do you have a minimal compileable snippet that produces the results you see? [code=c]#include <stdio.h> struct f_c_8 { union { float f; unsigned char c[8]; } u; }; struct f_c_8 Time = {{123.456}}; int main() { fprintf (stdout, "Time: %f\n", Time); fprintf (stdout, "Time: %f\n", Time.u); … |
Re: [ICODE]rand[/ICODE] has [ICODE]RAND_MAX[/ICODE], maybe [ICODE]random[/ICODE] has something similar. [url]http://c-faq.com/lib/randrange.html[/url] [url]http://c-faq.com/lib/rand48.html[/url] | |
Re: [QUOTE=poncho4all;950549]you could try [code]system("pause");[/code] or [code]#include <conio.h>//this library is needed for getch() getch();[/code] right before the return command on your main[/QUOTE] The [ICODE]system("pause");[/ICODE] version is frequently panned, and [ICODE]<conio.h>[/ICODE]/[ICODE]getch();[/ICODE] is ancient and nonportable. So these "fixes" happen to be pretty low on the totem pole. [url]http://www.daniweb.com/forums/showthread.php?p=780810&highlight=system+pause#post780810[/url] [QUOTE=bishop101;950559]Do I always have … | |
Re: [QUOTE=esesili;949125]"[B]patient1.output(cout);[/B]" works correctly it gets [B]doctor_hour_fee[/B] from [B]doct1[/B] object. The problem is at [B]patient2.output(cout);[/B]. When I enter patient information it asks me to enter all member variables of doctor object and it creates a new doctor, so that doct1 and new doctor are different and normally I get wrong answer. … | |
Re: Add some statements to display various parameters at key points in the function. For example, [code]float wk7recur (float value, int num) { [COLOR="Red"]cout << "wk7recur(" << value << ", " << num << ")\n";[/COLOR] if ( num == 0 ) { [COLOR="Red"]cout << " num == 0\n";[/COLOR] return 1; } … | |
Re: [QUOTE=Salem;948972]IMO, you should learn how to do this kind of thing with a std::string, rather than running to c-style strtok() for short-term convenience. You only typed a few lines, and it blew up anyway.[/QUOTE] [QUOTE=imwan;949004]I have changed my code exactly the way both the replies have said.[/QUOTE] [QUOTE=imwan;949661]still the problem … | |
Re: [QUOTE=happygeek;942810]Looks like someone has taken the daniweb name on Twitter (back at the end of 2008) although the account is hardly active with 1 foreign language post and just the 1 follower.[/QUOTE]*Whew* I had to make sure it wasn't my [URL="http://twitter.com/daniweblog"]Daniweb Twitterbot[/URL]. That description didn't resemble that bot, but I … | |
Re: [QUOTE=no1zson;941597]Would an "acceptable" use of GOTO be to rerun the entire main loop?[/QUOTE]No. [QUOTE=no1zson;941597]If I make it all the way through my logic, and simply want to start over at the top, would not a simple GOTO back to the top be the best option?[/QUOTE]Try to think about the real … | |
Re: [url]http://groups.google.com/group/comp.lang.c++/browse_thread/thread/25bc613dfbf72dc2/be4b67885161b012?ie=UTF-8&q=group:comp.lang.c%2B%2B+const+class+member+constructor+array#be4b67885161b012[/url] [edit][code=c++]#include <iostream> #include <vector> #include <algorithm> #include <iterator> class T { const std::vector<double> DefaultForward; public: T(const std::vector<double> &dfinit) : DefaultForward(dfinit) { } friend std::ostream& operator<< (std::ostream &o, const T& t) { std::copy(t.DefaultForward.begin(), t.DefaultForward.end(), std::ostream_iterator<double> (o, ",")); return o; } }; int main() { const double init[3] = {0.0,1.0,0.0}; const … | |
Re: If I rolled a quick "simulation" of these classes as follows, would it help clarify things? [code=cpp]#include <iostream> #include <string> class QApplication // real definition probably in <QApplication> { public: QApplication(int argc, char *argv[]) { std::cout << "QApplication ctor" << "\n"; } }; class QLabel // real definition probably in … | |
Re: [url]http://www.parashift.com/c++-faq-lite/operator-overloading.html[/url] | |
Re: [QUOTE=NRaf;943339]It seems that the matrix (int** matrix) is being passed by value; therefore when I play with it in the function, it's changing a different memory location so the original remains unchanged. How can I solve this?[/QUOTE]Either return matrix or pass a pointer to it as a parameter to this … | |
Re: Dunno if something like this is in the ballpark: [code] for ( int i = 0; i < 20; ++i ) { printGrid2(life); determineNextGen(life,life2); memcpy(life, life2, sizeof life); }[/code] | |
Re: "[URL="http://c-faq.com/lib/srand.html"]Note also that it's rarely useful to call srand more than once during a run of a program; in particular, don't try calling srand before each call to rand, in an attempt to get ``really random'' numbers.[/URL]" | |
Re: [QUOTE=invisal;939353]You can't simply compare 2 strings with operator ==. There is a function in library <string> called strcmp(). [code] Syntax: int strcmp(string1, string2) Return: Return 1 if string1 > string2 Return 0 if string1 == string2 Return -1 if string1 < string2. [/code][/QUOTE]FWIW, the standard definition for the return value … | |
Re: [QUOTE=Hiroshe;940444][URL="http://www.cplusplus.com/reference/clibrary/cstring/memmove/"]memove()[/URL] does not return anything[/QUOTE][aside]Take a closer look at that linked reference. | |
Re: [URL="http://cryptm.org/~hpb/media/hello1_x.wav"]Hello[/URL]. | |
Re: [url]http://c-faq.com/expr/precvsooe.html[/url] | |
Re: [url]http://www.parashift.com/c++-faq-lite/operator-overloading.html[/url] | |
Re: [QUOTE=poncho4all;940390]you can also use only the [code]fstream test; test.open("name of file") while(!test.eof)//.eof means while is not the end of file. { //condition } [/code][/QUOTE] That would be a step backwards. [url]http://www.daniweb.com/forums/post155265-18.html[/url] | |
Re: A common way to separate a number into digits is to use [ICODE]%[/ICODE] and [ICODE]/[/ICODE] like this. [code]#include <stdio.h> int main() { int i; for ( i = 1; i <= 100; ++i ) { int value = i; printf("value = %d\n", value); while ( value ) { [COLOR="Red"]int digit … | |
Re: [QUOTE=Hiroshe;937036]That would be cheating. :P I want to see what can be done with standard C alone.[/QUOTE]Prepare to be disappointed. ;) [url]http://c-faq.com/osdep/cbreak.html[/url] | |
Re: [url]http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_linklist.aspx[/url] | |
Re: Is [URL="http://cboard.cprogramming.com/c-programming/118247-mode-array.html"]MV1[/URL] any [URL="http://forums.devshed.com/c-programming-42/mode-of-an-array-629580.html"]relation[/URL]? | |
| |
Re: [QUOTE=MrNoob;938456]now i have my other function which i get runtime error on i don't why though [code] #include <stdio.h> #include <string.h> int ParseCh(char *S,char *buff,int num,char *End) { int i,temp; for(i=0;S[i]!=0;i++) { if(S[i]==',' || S[i]=='\n' || S[i]=='\t' || i==num) { temp=1; End=S+1; [COLOR="Red"]S[i]='\0';[/COLOR] break; } } if(temp) strcpy(buff,S); else { … | |
Re: With the two loops, while and for, you are essentially discarding [icode]pop[/icode] before you get to the for loop. Your if-tree uses [icode]||[/icode] where you mean [icode]&&[/icode]. [code] cout << "\t\t\tPrarieville Population Growth\n"; for ( int years = 1900; years <= 2000; years = years + 20 ) { inputFile … | |
Re: What are you doing to tell the difference between "opens the file and then has nothing more to do to closes it and exits the program" and "fails to open the file"? BTW, you may be interested in [URL="http://www.daniweb.com/forums/thread90228.html"]this[/URL] shortly. | |
Re: [QUOTE=sara9111;936262]What the diffrent bettween while looping, conter-controlled while loop, sentinel-controlled while loop,flag-controlled while loop, do while loop and For loop. when we use each one of them???[/QUOTE]A [ICODE]for[/ICODE] loop tends to lend itself to things which need to be done x number of times: [code]for ( i = 0; i … | |
Re: Something akin to [URL="http://www.daniweb.com/code/snippet281.html"]this[/URL]? | |
Re: Once you're off in the land of undefined behavior, strange things can happen. In this case, I believe I need to reverse the declaration order to see which particular thing you may be seeing. That is, [code] int i=0, a[100];[/code] [quote]... 100 101 102 103 6 7 8 ...[/quote]This might … | |
Re: > Uhh... what are you doing? pow() returns an integer. [pow](http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.5.5.1) | |
Re: Your pointer is initialized in a screwed-up way. I think you've got bigger fish to fry first. What do you think you're trying to do with your 'bit array' that isn't already done with masks? | |
Re: Perhaps keep track of the last non-null string: [code]#include <string.h> int main(void) { char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL[COLOR="Red"], *last[/COLOR]; result = strtok( str, delims ); … | |
Re: Hmm. Maybe take a look at [URL="http://eternallyconfuzzled.com/jsw_home.aspx"]the tutorials here[/URL]. ;) | |
Re: [QUOTE=amegahed3;933998]So?[/QUOTE]I'm guessing that in excess of ~356,400,000 bytes on the stack [I]might possibly[/I] contribute to a stack overflow. [QUOTE=amegahed3;933998]My code (a file called program.cpp) and the .cpp and .h files of the library I'm using are all included in the attached .zip file.[/QUOTE] Maybe not quite all? [quote]hist.cpp In file … | |
Re: [code]for(i=0;i<40;i++)[COLOR="Red"]; /* extraneous semicolon */[/COLOR][/code] | |
Re: [url]http://c-faq.com/aryptr/index.html[/url] | |
Re: [URL="http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.10"][18.10] What is a "const member function"?[/URL] | |
Re: A brief note on signals and calling standard library functions: [url]http://groups.google.com/group/comp.lang.c/browse_thread/thread/00d5082d648b2437/a4d67511412817da#a4d67511412817da[/url] [edit]Doing some more digging, I found [URL="http://en.wikipedia.org/wiki/Signal.h#Member_functions"]this[/URL]: [quote=Wikipedia]The function func may terminate by executing a return statement or by calling the abort, exit or longjmp functions. [COLOR="Red"]If func executes a return statement, and the value of sig was SIGFPE … | |
Re: [url]http://forum.codecall.net/c-c/19344-how-redo-same-code-using-structs.html[/url] | |
Re: [QUOTE=jephthah;920287]it's like he just hit the ground and started kicking ass without any warmup period.[/QUOTE]Forums ain't exactly the bleeding edge of teh intertubes. You don't need a "warmup period" when you've already been doing this kinda thing for years (if that is the case, which might be my assumption). ;) | |
Re: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13[/url] | |
Re: [url]http://www.daniweb.com/forums/thread204368.html[/url] | |
Re: [QUOTE=VernonDozier;923838]I forget the exact criteria where >> returns true and false. I think it may be if any of these three bits are set, >> fails, but don't quote me.[/QUOTE][url]http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.4[/url] | |
Re: [QUOTE=Ancient Dragon;892346]%i is the same as %d, they are interchangeable but I believe %d is more common.[/QUOTE]They are the same for [ICODE]printf[/ICODE], but they are different for [ICODE]scanf[/ICODE]. Both are used for integers, though. [ICODE]%i[/ICODE] may read the input as hexadecimal or octal as well as decimal. |
The End.