2,384 Posted Topics
Re: I'd suggest writing/reading each structure member in text form. | |
Re: Try [FONT=Fixedsys]clock[/FONT] inistead of [FONT=Fixedsys]time[/FONT] ([FONT=Fixedsys]time[/FONT] needs only be accurate to the nearest second). [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1048385167&id=1043284392[/url] Also, your may want to consider using the same seed for populating the array to compare each function. That way, each array of random numbers would be the same for each sort. | |
Re: [code]#include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; vector<double> *func() { static const double init[] = {1.0,1.5,2.0,3.3}; vector<double> *vec = new vector<double>(init, init + sizeof init / sizeof *init); return vec; } int main() { vector<double> *p = func(); copy(p->begin(), p->end(), ostream_iterator<double>(cout, "\n")); return 0; } /* … | |
Suggestion: I like the language tags [url=http://www.gidforums.com/t-689.html]here[/url]. I've also seen them on cpp-home. Is something like this already on any wish list for Daniweb? | |
Re: What do you mean by "control-break"? [url=http://en.wikipedia.org/wiki/IBM_PC_keyboard]Here[/url] it states,[quote][I]Pause/Break[/I]- CTRL-BREAK traditionally stopped programs.[/quote]I don't imagine you want to quit the program, so I could guess that you want to insert a pause. If so, just take and discard user input at the point you want, like [url=http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042856625&id=1043284385]this[/url]. | |
Re: If you're writing Turbo C code for DOS, use Turbo C for DOS. | |
Re: [url]http://www.google.com/search?q=cube+root+algorithm[/url] | |
Re: A shot into new (pun!) territory for me. [url=http://www.relisoft.com/book/tech/9new.html]Here[/url] (way down at the bottom) it states,[quote]Since placement new doesn't allocate any memory, it's an error to delete the object created by it.[/quote]For the time being I've been going with [url=http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10]this[/url] method.[quote]ADVICE: Don't use this "placement new" syntax unless you have … | |
Re: [url]http://www.embedded.com/98/9804fe2.htm[/url] | |
Re: Why are you trying to do the same thing twice? How about doing some [FONT=Courier New]if(file.is_open) { /* ... */ }[/FONT] around the second attempt? | |
Re: I can't get that far without a definition of [FONT=Courier New]account[/FONT], but your prototype doesn't match the definition. | |
Re: >px0c0 and px0c1 are type double pointers How's your allocation of memory to px0c0 and px0c1? | |
Re: If you're trying to read from a file, use some function that will read from a file. Sitting at the beginning of a file and waiting for the end to come will not do much.[code]#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream … | |
Re: Only define [FONT=Courier New]Cars[/FONT] once.[code]struct Car { int number, miles; float gallons; float averagegallons; }[COLOR=Red]Cars[/COLOR]; Car [COLOR=Blue]Cars[/COLOR][MAXCARS];[/code]Then figure out which way to use them.[code]getdata([COLOR=Red]Cars[/COLOR].number, [COLOR=Red]Cars[/COLOR].miles, [COLOR=Red]Cars[/COLOR].gallons); putdata([COLOR=Red]Cars[/COLOR].number, [COLOR=Red]Cars[/COLOR].averagegallons);[/code] | |
Re: Make the function definitions match the prototypes or vice versa. | |
Re: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392[/url] | |
Re: This is something I'd quickly made the other day (pursuing a question in another forum, which is why it may look entirely unrelated). [code]#include <stdio.h> struct stack { size_t size; int array[5]; }; struct stack mystack; int push(int value) { printf("push(%d)\n", value); if ( mystack.size < sizeof mystack.array / sizeof … | |
Re: For [FONT=Courier New]double[/FONT]s, use specifiers for [FONT=Courier New]double[/FONT]s, not [FONT=Courier New]int[/FONT]s.[code] sscanf(res,"%[COLOR=Blue]lf[/COLOR] %c %[COLOR=Blue]lf[/COLOR]",&op1,&opp,&op2); printf("%[COLOR=Blue]g[/COLOR]\n",op1); printf("%c\n",opp); printf("%[COLOR=Blue]g[/COLOR]\n",op2); printf("====\n"); printf("%[COLOR=Blue]g[/COLOR]\n",pow(op1,op2)); /* the output is for sure 2 */[/code] | |
Re: This is not likely ever to be true.[code]*str != EOF[/code]The first loop goes to the end of file, right? Then the second loop never has anything to read, right? When do you expect to get anything different for this?[code] if (97 <= (static_cast<int>(tolower('a'))) <= 122) alphabet[static_cast<int>('a') - 97]++;[/code]That is, when … | |
Re: [code]char [COLOR=Red]*[/COLOR] cmd="ls -l";[/code]This should be:[code]char cmd[COLOR=Blue][][/COLOR] = "ls -l";[/code] | |
Re: Well, your [FONT=Courier New]getstring[/FONT] returns a single [FONT=Courier New]char[/FONT] and not a [FONT=Courier New]char*[/FONT]. [code]/* grabs a string from the command prompt */ [COLOR=Red]char[/COLOR] getstring (char strquestion[255]) { /* reset */ char lineofinput[255]; if (strlen (strquestion)) printf ("%s", strquestion); fgets (lineofinput, sizeof (lineofinput), stdin); /* while we get an empty … | |
Re: Answer: Use [url="http://www.google.com/search?sourceid=navclient&q=cin%2Egetline"]Google[/url] to find a [url="http://www.cplusplus.com/ref/iostream/istream/getline.html"]reference[/url]. | |
Re: Post your initial attempt, we have to start somewhere. | |
Re: [url=http://cboard.cprogramming.com/showthread.php?p=457428#post457428]..........[/url][QUOTE=Prelude]>C sucks Don't make me go Narue on you. ;)[/QUOTE] | |
Re: First, I think those semicolons should be removed. [code] for (i = 1; i < cnt; i++)[COLOR=Red];[/COLOR] { for (j = 0; j < cnt - i; j++)[COLOR=Red];[/COLOR] {[/code]Second, why not throw in some debugging output statements and see for yourself? [code]#include <stdio.h> [COLOR=Blue]void show(const int *array, int cnt) { … | |
Re: [QUOTE=JoBe]1) QUESTION IS: how can a pointer be NULL or 0 when it's an adress wich gives a value? Because, as I understand it to be like this: [code]Expression----------------Type--------------Value p-------------------------pointer-to-double--an adress *p------------------------double-------------(12.34)[/code] Or, is it saying that when declaring p = NULL;, the adress of that pointer is 0x00000000 and … | |
Re: Sorry, I've just taken a cursory look.[QUOTE=jhdobbins]There is a problem with the enum file aGrade im sure but I'm not exactly sure how to fix it...[/QUOTE]Should [FONT=Courier New]tmp[/FONT] be an [FONT=Courier New]aGrade[/FONT], should [FONT=Courier New]mycourses[j+1].grades[/FONT] be a [FONT=Courier New]char[/FONT], or do you need to convert from a [FONT=Courier New]char[/FONT] to … | |
Re: >What do these errors mean? They mean you refer to these identifiers in your code, but never define them. Perhaps they are only declared or, in the case of the constructors, are defined with different parameters. | |
Re: FAQ > How do I... (Level 3) > [url=http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608]Accessing a directory and all the files within it[/url] FAQ > *nix Specific > [url=http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047077601&id=1045780608]Working with files and directories[/url] | |
Re: My compiler shows something similar after fixing this oddity. [code]employee.gross[COLOR=Red]ddd[/COLOR] = employee.rate * employee.hours;[/code]So the linker says it can't find these functions. Let's look at what we have.[code]void getdata([COLOR=Blue]char[/COLOR] [], int, float, int); void putdata([COLOR=Blue]char[/COLOR] [], int, float); // ... void getdata([COLOR=Red]int[/COLOR] name[], int number, float rate, int hours) { … | |
Re: [QUOTE=jhdobbins][Linker error] undefined reference to `WinMain@16'[/QUOTE]Sounds like prime keywords for a [url=http://www.daniweb.com/techtalkforums/search.php?searchid=365618]search[/url], which might turn up some [url=http://www.daniweb.com/techtalkforums/showthread.php?t=21545-WinMain%4016]relevant hits[/url]. | |
Re: Match each [FONT=Courier New]{[/FONT] to its [FONT=Courier New]}[/FONT]. Are you trying to do a [FONT=Courier New]do...while[/FONT] loop without the [FONT=Courier New]do[/FONT]? [code]float multiply_num(float number) { float i, j; char return_main; if(number == 0) { cout << "Enter number to multiply "; cin >> i; cout << " times "; cin … | |
Re: > I am working on a project on playing cards using enum and class. I really need help with the function defination in this project, > Here i will attach the question, your help will be highly appreciated. You can get bac to me trough jeymineb at yahoo.co.uk. > Thanks. … | |
Re: You may want to choose a different name other than [FONT=Courier New]time[/FONT], but since you are adding minutes, wouldn't it be like this?[code]mytime operator+ (int min)[/code] | |
Re: [QUOTE=Fasola]those resources aren't free :([/QUOTE]Dinkumware is. | |
Re: [code]ostream& operator<< (ostream& os, [COLOR=Blue]const AirborneLocation&[/COLOR] plane)[/code][code]os << "\tDistance to plane: " << [COLOR=Red]plane.distance()[/COLOR];[/code]Does [FONT=Courier New]plane.distance()[/FONT] return an [FONT=Courier New]AirborneLocation[/FONT]? Or should it be called like this?[code]os << "\tDistance to plane: " << plane;[/code]And shouldn't [FONT=Courier New]operator<<[/FONT] return [FONT=Courier New]os[/FONT]? | |
Re: [QUOTE=Narue]Accelerated C++ by Andrew Koenig and Barbara Moo[/QUOTE]Top of [thread=10232]this list[/thread]! Do you consider that list fairly accurate? | |
Re: >could anyone provide me the basic code to display "hello world" in a window? Does your compiler offer to do this for you? [URL=http://img175.echo.cx/my.php?image=hello4nk.jpg][IMG]http://img175.echo.cx/img175/5527/hello4nk.th.jpg[/IMG][/URL] >and if possible a link to the code necessary to use window api for c++ programs. Have you checked your compiler's documentation? It should be the … | |
Re: C isn't C++, so C doesn't have constructors or the [FONT=Courier New]std::string[/FONT] type. You may get away with something like this. [code] String ExitString [COLOR=Blue]= "QUIT"[/COLOR]; /* ... */ do { PromptForGuest (inputName); } while ( [COLOR=Blue]strcmp[/COLOR](inputName, ExitString) )[COLOR=Blue];[/COLOR][/code]Personally, I don't care for the [FONT=Courier New]String[/FONT] typedef, I think it … | |
Re: [code]float fun(float [COLOR=Red]arr[/COLOR][][1],float [COLOR=Blue]arr[/COLOR][][3]){ arr[i][5]=(arr[i][1]/arr[i][2]); return arr[i][5];}[/code]Which is who? Proper formatting such as indenting and whitespace can also make it a whole lot easier to read your own code to find mistakes. | |
Re: There will be ambiguity with your class and [FONT=Courier New]std::vector[/FONT] since you are [FONT=Courier New]using namespace std[/FONT].[code]struct [COLOR=Blue]vector[/COLOR] { double x; double y; friend ostream& operator<< (ostream&, [COLOR=Blue]vector[/COLOR]); }[COLOR=Red][SIZE=5];[/SIZE][/COLOR][/code]If you still want to grab the whole namespace, I think you can disambiguate like this.[code]friend ostream& operator<< (ostream&, [COLOR=Blue]::[/COLOR]vector);[/code] | |
Re: [QUOTE=Starz20]This is what I have written, but if I type in "E" to exit, it loops to enter in a number again and doesn't exit.[/QUOTE]I don't see the loop, but [FONT=Courier New]"E"[/FONT] is not a valid [FONT=Courier New]float[/FONT] number. If you want the possibility of the user input to be … | |
Re: [QUOTE=alc6379]Also, I'm sure Narue might mention this, but I know you're not supposed to use void main(). I'm not entirely sure why, and I don't want to guess, but I have an idea why. Care to elaborate further on this, Narue?[/QUOTE]I'm not Narue, but I try to be that good. … | |
Re: An [FONT=Courier New]int[/FONT] divided by an [FONT=Courier New]int[/FONT] results in an [FONT=Courier New]int[/FONT] using [FONT=Courier New]int[/FONT] division.[code]struct Car { [COLOR=Magenta]int[/COLOR] number, miles; [COLOR=Magenta]int[/COLOR] gallons; float averagegallons; }; /* ... */ Cars[i].averagegallons = [COLOR=Magenta]Cars[i].miles / Cars[i].gallons[/COLOR];[/code]To keep them as [FONT=Courier New]int[/FONT]s, cast one of the operands; this will cause the division … | |
Re: Since choice is an [FONT=Courier New]int[/FONT], compare it with [FONT=Courier New]1[/FONT], [FONT=Courier New]2[/FONT], and [FONT=Courier New]3[/FONT] -- not with characters [FONT=Courier New]'1'[/FONT], [FONT=Courier New]'2'[/FONT], and [FONT=Courier New]'3'[/FONT]. | |
Re: It sounds like you had originally specified a (GUI) Windows application, but provided code for a console application. The GUI app expects [FONT=Courier New]WinMain[/FONT], the console app expects [FONT=Courier New]main[/FONT]. It may be easiest to create a new project as a Windows Console Application, and then add your existing source … | |
Re: I miss this little feature: [IMG]http://img198.exs.cx/img198/6823/forumjump2fw.jpg[/IMG] It gives a bit of an "Explorer" ability. [URL=http://img205.exs.cx/my.php?loc=img205&image=devshed8sy.jpg][IMG]http://img205.exs.cx/img205/7894/devshed8sy.th.jpg[/IMG][/URL] | |
Re: [QUOTE=Fasola]what does -> mean, when you wrote temp->data = item; ?[/QUOTE]It is used to access a member of a class/struct/union from a pointer rather than from the object itself -- which uses the [FONT=Courier New].[/FONT] operator.[code]#include <stdio.h> struct type { int member; }; int main(void) { struct type object = … | |
Re: With the title...[QUOTE=nizar4445]Heeeeeeeeeeeeeeeeelp :cry: :cry: :cry: hello all can anybody help me pleeeeeeeeeeeeeeaaaaaaazzzzzzzzzz!!!!![/QUOTE]This generally causes a thread to be widely ignored. [QUOTE=nizar4445]Create a program that will allow the user to enter and analyse a set of data collected from an experiment. The data is to be entered by the user … | |
Re: I think you are ignoring what happens in the [FONT=Courier New]switch[/FONT].[code] float xCount = 0; float yCount = 0; float zCount = 0; switch( szBuf[i] ) { /* ... */ } xCount = g_pVertices[index].x; yCount = g_pVertices[index].y; zCount = g_pVertices[index].z;[/code]Before the [FONT=Courier New]switch[/FONT], you initialize them all to zero. After … |
The End.