1,174 Posted Topics
Re: [code]int put_element(int i, int j) { // check here that both i and j are within the bounds // you currently have allocated ... // And remember that indexes are zero-based, i.e. // if you have 'int arr[2]', the last valid index is 1 (not 2) return p[i][j]; }[/code] | |
Re: In your show_costs() function ... [code] int scrub; if(n[[COLOR="Green"]some_valid_subscript_here[/COLOR]] < 5) { // what is the value of [B][COLOR="Red"]scrub[/COLOR][/B] here? // and where does it come from?? n[scrub] == c; scrub++; } [/code] | |
Re: Try the following ... <a href="file:///c:/test.csv">open test.csv</a> should work if you have the file c:\test.csv on disk. | |
Re: Maybe you could use strtod() as a 'workhorse' and switch to using a double instead of integer. See [url]http://www.cplusplus.com/reference/clibrary/cstdlib/strtod.html[/url] For example, [code] char myStr[30] = ""; while(1) { cout << "Enter a decimal number: (q to quit)" << endl; cin.getline(myStr, 30); if('q' == *myStr) { break; } char * endptr … | |
Re: An introduction to classes can be found e.g. here [url]http://www.cplusplus.com/doc/tutorial/classes.html[/url] [QUOTE=Queen of Dreams;555770] how to write answer with CLASS... [/QUOTE] To output something to screen, even from within your class, you can use cout. An example: [code] #include <iostream> using namespace std; int main() { int value = 123; cout … | |
Re: The following can also be done .. it does not involve strcpy() or arrays, instead it uses a single pointer (real_out_ptr) [code] char const * real_out_ptr = "This REALLY shouldn't have happened.\n"; int output_type = 1; if (output_type == 1) real_out_ptr= "binary"; else if (output_type == 2) real_out_ptr = "octal"; … | |
Re: Seems that operator << is unable to take a 'photon' as input. You probably need to write something like: [code]std::ostream & operator << (std::ostream& s, const photon & p) { // stuff the content of the photon into the stream ... // s << p.abc << etc ... return s; … | |
Re: Change swap([B][COLOR="Red"]&[/COLOR][/B]string_array[i], [B][COLOR="Red"]&[/COLOR][/B]string_array[i-1]); to swap(string_array[i], string_array[i-1]); because swap() expects two pieces of 'char*', not 'char **'. | |
Re: If you will not be using MFC (for any reason), check out ZedGraph [url]http://sourceforge.net/projects/zedgraph/[/url] | |
Re: Call [code]swapArgs(&parmA,&parmB);[/code] again after [code]printf("Swapped values A=%d, B=%d.\n",parmA,parmB);[/code] | |
Re: p.level is an integer, hence %d instead of %s ... [code]int viewcharacter() { printf("Name:\t%s\n", p.name); printf("Level:\t%[B][COLOR="Red"]d[/COLOR][/B]\n",p.level); }[/code] | |
Re: Use substr(), to extract '1234', you could do: [code=cplusplus] const std::string Value10 = "Number(1234)"; const size_t start = Value10.find("("); const size_t end = Value10.find(")"); const std::string extracted = Value10.substr(start + 1, end - start - 1); cout << "extracted: " << extracted.c_str() << endl; [/code] In same, fashion you can … | |
Re: A couple of things, 1) you are using bitwise OR operator in [code]if((current[level-1]==n)[B][COLOR="Red"]|[/COLOR][/B](current[level+1]==n)) return false;[/code] You probably meant logical OR i.e. [code]if((current[level-1]==n)[B][COLOR="Red"]||[/COLOR][/B](current[level+1]==n)) return false;[/code] 2) and then usage of 'goto', you could throw away the 'mainloop' label and inside the for() loop replace goto mainloop; with break; and just delete … | |
Re: What do you mean by 'crashing'? Is it so that VirtualAlloc returns NULL and you are still using the pBuffer? Or something else? | |
Re: This is practially pretty much what Lerner said ... [code] std::string Value = "a,b,c,d,e,f"; istringstream is(Value); std::string s; std::vector<string> v; while (getline(is, s, ',')) { // add item v.push_back(s); } // iterate through the vector and output each item ... for(std::vector<string>::iterator it = v.begin(); it != v.end(); it ++) { … | |
Re: You'd probably want to use a loop for operating with user input, i.e. something like [code] // use an instance of btree class ... btree tree; // a Node pointer Node * nodeptr = NULL; do { cout << "Please enter a menu choice:\n" << "'A' - In-order Print\n" << … | |
Re: If you open a command prompt (cmd.exe) and type in e.g. gcc --version what happens? | |
Re: [code] int Func3 () { int Option; int A = 2; int B = 3; double C = 2.5; double D = 3.5; cout << " Enter your select: "; cin >> Option; if(1 == Option) { // Call func1() here } else if(2 == Option) { // Call func2() … | |
Re: Something like this ... [code]MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);[/code] | |
Re: Your main() is not returning an int, maybe nothing at all or something else, so .. [code]int main(int argc, char * argv[]) { // your code here // return some integer value, in this case zero ... return 0; }[/code] | |
Re: First things first, I second to WaltP, really format your code to make it readable. Now it's close to unreadable. Arrays are zero-indexed .. hence both of your string arrays now have an unused index 0, in other words, you should do with smaller (by one) string arrays. [code]string squares[] … | |
Re: Also the second operand really must be changed from while(strcmp(pt->next, [B][COLOR="Red"]' '[/COLOR][/B])!=0) to while(strcmp(pt->next, [B][COLOR="Red"]" "[/COLOR][/B])!=0) because C-compiler treats ' ' as an integer and strcmp() does not expect an integer. | |
Re: Just to give some basic ideas, you might do with the following simple setup, without linked lists involved at all. Use a structure like e.g. [code]typedef struct { const char * _pWord; // pointer to the word unsigned int _nFreq; // its frequency }Entry;[/code] To make it easy, have a … | |
Re: Since I don't know what the function is supposed to do, I cannot offer much advise. However, if you plan to change the values of the parameters passed into the function, you need to pass the parameters by reference, instead of by value. I.e. public char CheckDir(int [B]&[/B] row, int … | |
Re: Remove the [code]int Get_Number (int x);[/code] that is there on line 22. | |
Re: >> you can edit your first post. It seems that once posted, a post remains editable for some short period of time and then enters a non-editable mode. Is there any way, for one to edit one's own post regardless of how long it has been on the forum? By … | |
Re: Try following [CODE] [B]// Point.h[/B] class Vector; class Point { public: Vector GetVector(); }; ////////////////////////////////////////// [B]// Point.cpp[/B] #include "point.h" #include "vector.h" Vector Point::GetVector() { Vector v; return v; } ////////////////////////////////////////// [B]// Program.cpp[/B] #include <iostream> #include "Point.h" #include "Vector.h" using namespace std; int main() { Point P; Vector V; return 0; … | |
Re: Fix the flawed scanf_s() call to be like below: [code]double getdouble(char item[], double min) { ... printf("\nEnter a ticket %s greater than or equal to %d: ", item, min); scanf_s("%[B][COLOR="Red"]lf[/COLOR][/B]%*c", &ticketquan); ... [/code] Some calls to printf() are erroneous in the same way, i.e. you use %d to output a … | |
Re: >> Now I have another problem... I suspect that your code goes something like this; [code][B]{[/B] // <- start of a block (for some reason) ofstream fout; ... code ... [B]}[/B] // <- end of the block ('fout' does not exist anymore at this point) ... code ... // Report … | |
Re: You can use following: [code]char *p = "Hello World"; char c = *(p + 1); // 'e' [/code] | |
Re: fscanf() was missing one argument. [CODE] int main() { int i=0; [B][COLOR="Red"]int d=0;[/COLOR][/B] FILE *all; all = fopen(FILENAME1, "r"); while(fscanf(all,"%d", [B][COLOR="Red"]&d[/COLOR][/B])!=EOF) ... }[/CODE] | |
Re: >> function named MPG which [B]returns[/B] the number of miles a car can travel with one gallon of gasoline MPG() simply cannot be void, because it has to return the requested value. | |
Re: You have to change the initialization of [B]numbers[/B] [code] long count = 0; //counts the number of numbers in the input file long items = 0; long numbers[count];[/code] | |
Re: Could it be that comboBox2->SelectedItem is a NULL reference? Calling Box1->push_back() like you do is OK. | |
Re: After a ver quick look into the code, at least insideTriangle() uses uninitialized variables. [CODE] insideTriangle (double base, double height, double p_x, double p_y, double p_find_x, double p_find_y) { double aX, bX, cY, centerY; aX = base - p_x; centerY = [B][COLOR="Red"]cY[/COLOR][/B] - height; if (p_find_x <= [B][COLOR="Red"]bX[/COLOR][/B] && p_find_x … | |
Re: At the end of the program, try getting the length of the 'name' using strlen() i.e. [code] ... printf("%c",name[i]); printf("\nlength of name is: %d", strlen(name)); }[/code] | |
Re: It is faster/easier to locate the error spots in the code if you post the compiler errors too. | |
Re: [QUOTE=kylcrow;545269]Google does not help me, because all I can find is how to do this with a struct, not a class.[/QUOTE] The difference between a class and a struct is that, with a class everything is private by default, whereas with a struct everything is public by default. So you … | |
Re: What is the symptom of it 'not working' ? (Please be more precise about failures when you post). | |
Re: Here is a quite good explanation for sheets/pages: [url]http://support.microsoft.com/kb/300606[/url] | |
Re: Remove the & operator, tempString as such must be used in that scanf (tempString is a pointer, hence no need for &). [code]scanf("%s", [B][COLOR="Red"]&[/COLOR][/B]tempString);[/code] Then allocate memory [B]before[/B] copying. [code]temp->artist = (char*) malloc(strlen(tempString)+1); strcpy(temp->artist, tempString);[/code] You may want to check that malloc() actually succeeded, (i.e NULL != temp->artist). Also remember … | |
Re: [code]const char const * strings[] = {"abcdeedcba\n","abcdxxdcba\n","abcxxxxcba\n","abxxxxxxba\n","axxxxxxxxa\n", NULL}; for(char const ** ptr = strings; *ptr; ++ptr) { printf(*ptr); } [/code] | |
Re: Please post the error message exactly as it is displayed. The computer probably lacks one or more .dlls that your program needs. | |
Re: Post the code that shows how you have initialized the user struct + buffer and what are the crazy values? | |
Re: Try seeing which error code WSAGetLastError() returns, error codes are listed in [url]http://msdn2.microsoft.com/en-us/library/ms740668(VS.85).aspx[/url] | |
Re: Should you check that the SelectedItem is not a null reference. | |
Re: atum.cpp is a source file, not an executable file. You should locate the program you have compiled i.e. the executable file. | |
Re: Look at the for loop's condition for(i=0;[B][COLOR="Red"]i<4[/COLOR][/B];i++) i.e. "i" is not less than four at that line. | |
Re: If you need to "find the Last "/" in the string" try using the std::string::find_last_of() to get index of the last slash in a string. For details see e.g. here [url]http://www.cplusplus.com/reference/string/string/find_last_of.html[/url] | |
Re: [QUOTE] what this function mean [code] operator T*() {return data_;} [/code][/QUOTE] It returns a pointer to the member variable data_ of the array class. |
The End.