1,494 Posted Topics
Re: Well to print a row you would hold the row index constant and then vary the column from 0 - max_column...So to print a column you would hold a column constant and vary the row from 0 - row_max. For row 2, i varies from 0 - max_column my_arr[2][i] for … | |
Re: Put this line before the function player2 [code] int player1(void); [/code] | |
Re: Try something like this [code] #include<stdio.h> int main() { int i = 0; char p[10][10]; printf("please enter 10 words\n"); for(i = 0; i < 10; i++) { fgets(&p[i][0], 10, stdin); printf("\n"); } for(i = 0; i < 10; i++) { printf("%s", &p[i][0]); printf("\n"); } return 0; } [/code] A few … | |
Re: you had an error in your structure declaration and a questionable variable. [code] #include<stdio.h> #include<stdio.h> typedef struct contact { char name[1][20];/*why do you have this*/ struct number { double num; }no; } myc; int main() { myc thec; thec.no.num = 1234; fprintf(stdout, "num->%f\n", thec.no.num); return 0; } [/code] | |
Re: You really should use a library like XDR(external data representation) to pass data across a network. It'll ensure that the network byte order is maintained. | |
Re: Try this [code] MessageBox(NULL, L"Text", "Title", MB_OK | MB_ICONEXCLAMATION); [/code] | |
Re: Try this for Main line 13. [code] testHand[0].addCard(testDeck.dealCard()); [/code] | |
Re: First, you'll have to create a < operator for your class and then you'll have to create a function that compares two objects of that class using the < operator and then call the sort algorithm sort(your_vector.begin(), your_vector.end(), sort_function); Here's a simple example [code] #include <iostream> #include <vector> #include <algorithm> … | |
Re: Before you concern yourself with averages I would get your while loop working, as it is you read the last grade twice. Try changing your loop condition to something like... [code] while( fscanf(infile, "%d", &numA) != EOF) [/code] | |
Re: Yes to all your questions. C is a general purpose programming language. | |
Re: Could you please clean up your posted code. Its almost impossible to read. Your problem, by the way [code] void getDerivative() (double [],int[]); [/code] should be [code] void getDerivative(double [],int[]); [/code] | |
Re: Try something like below [code] #include<stdio.h> int main () { int id = 0; float value1 = 0; float value2 = 0; while(id<=3) { printf("Please enter the id number - 1 to 2 - to end\n"); scanf("%d",&id); switch(id) { case 1: value1 = 10 * 10; printf("Value1 is: %f\n",value1); break; … | |
Re: I see a problem right away [code] char list[9][31]; char sorted[9][31]; //--------Main Program Body---------- cout << "****Alphebetical Sorting Program***"<<endl<<endl; cout<<"please enter 10 strings you wish to sort"<<endl; [/code] Your arrays are 9 X 31 and should be 10 X 31. | |
Re: Like so [code] char my_ch = string[2]; [/code] | |
Re: It could be 'appearing' to hang because the algorithm is very inefficient and its taking a long time to calculate the bigger perfect numbers. Let it run for a few hours. | |
Re: Try adding this [code] #include <iostream> #include <cmath> using namespace std; int main() { double root1, root2, a, b, c, root; cout << "Enter the coefficients a, b, c: "; cin >> a >> b >> c; root = sqrt (b*b - 4.0*a*c); root1 = .5*(root - b) / a; … | |
![]() | Re: Firstly, on line 68 [code] newloc=malloc(sizeof(struct bstree *)); [/code] your allocating memory for the size of a pointer not the size of struct bstree..It should be [code] newloc=malloc(sizeof(struct bstree)); [/code] ![]() |
Re: I would try simplifying your code... [code] #include <stdio.h> #include <stdbool.h> #include <ctype.h> #include <string.h> bool isValidNum( char str[] ) { int i = 0; for (i = 0; i < strlen(str); ++i) { if (!isdigit(str[i])) return false; } return true; } int main() { char string[] = {'\0','\0','\0','\0','\0'}; printf("%d", … | |
Re: I tried this and got 1311780402. [code] #include <stdio.h> union myu { unsigned int x; char ch[4]; }; int main() { union myu the_u; the_u.ch[0] = 50; the_u.ch[1] = 46; the_u.ch[2] = 48; the_u.ch[3] = 78; fprintf(stdout, "x->%u\n", the_u.x); return 0; } [/code] | |
Re: Try doing it like below [code] #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct mystruct { int a; }mytype; mytype* createMytype(int x) { mytype *mt; mt = (mytype*)calloc(1, sizeof(mytype)); mt->a = x; return mt; } int foo(mytype** mt) { *mt = createMytype(6); return 0; } int bar(mytype** mt) { printf("%d\n", … | |
Re: Well first things first...This is C++ and not C, just look at your for statements and your includes. | |
Re: Try writing some simple programs and find out for yourself. | |
Re: I don't know why people have such difficulties with pointers. A pointer is a variable, its just like an integer variable except the values are memory addresses and the language C allows dereferencing pointers to obtain the value that's pointed to. Simple right? Now your question. If you perform these … | |
I have a question about function precedence. How does the compiler decide which function to call in quasi ambiguous situations? Is it laid out in the standard or is it implementation dependent? If you look at the attached code you'll see I'm outputting the value contained by the myint object. … | |
Re: No your data is safe. When you reassign pointer, its just gets the address of your string "weeeeeeeeeeeeeeeeeeeeeee". "hi" - has one address value. "weeeeeeeeeeeeeeeeeeeeeee" - is another address value. | |
Re: I was playing with this a while ago...quite a while ago so I can't guarantee that any of this code will work.. Here's the code that I used. mywrap.c [code] #include <Python.h> extern int intlimit(int); extern int glblimit(int); extern void* intbase(unsigned long); extern void* glbbase(unsigned long); extern unsigned long myfunc(void*); … | |
Re: I think you want a conversion operator..I think? Try looking up this link and see if its what your after.. [url]http://www.devx.com/tips/Tip/12459[/url] | |
Re: Try changing your array to.. int test[2][2][2]; Try running this code below [code] #include <stdio.h> #include <stdlib.h> int test[1][1][1]; int test2[2][2][2]; int main() { fprintf(stdout, "array elements->%lu\n", sizeof(test)/sizeof(int)); fprintf(stdout, "array elements->%lu\n", sizeof(test2)/sizeof(int)); return 0; } [/code] | |
Re: Here's what I would do in the for loop [code] pointer[0].health = some_value; pointer[0].armor = some_value; pointer[0].nextaddr = &pointer[1]; [/code] Instead of using the constants 0,1 for the array indexes, use variables that increment in the for loop. Also make sure you remember that the last node points to nothing(NULL). | |
Re: Can you show us how your calling insertHead()?...Ooops, its line 16 of the posted code. Your assigning struct node *n to newNode->data. Is newNode->data an int? | |
Am I correct assuming that a reference to an object will not call the object's destructor when the reference goes out of scope? The code I attached supports my assumption but I'm not certain if its correct...Any comments? [code] #include <iostream> class myint { public: myint():itsvalue(0) {} myint(unsigned long val):itsvalue(val) … | |
Re: Google is your friend. [url]http://www.suite101.com/content/procedure--subroutine-or-function--a8208[/url] | |
Re: You should be able to call the destructor which should call delete of the variable that points to the next node. | |
Re: This functionality exists as a language extension so it depends on which compiler your using...So which compiler are you using? | |
Re: Line 7 [code] int area = (p(p - a)(p - b)(p - c))/2; [/code] should probably be [code] int area = (p * (p - a) * (p - b) * (p - c))/2; [/code] also line 13 your calling [code] convert(); [/code] You haven't defined a function convert. | |
Re: You could start by telling us what the problem is.. | |
Re: You define, on line 123 char line[50]; And then use fgets on line 139 fgets(line,20,file) Why? I tried compiling your program and received these two warnings In function ‘count’: 111: warning: control reaches end of non-void function In function ‘table’: 49: warning: control reaches end of non-void function Both functions, … | |
Re: You have to pass the memory location that contains the pointers to the cstrings. If you think about it, it makes sense. Here's a big hint. If you were to define your function like below void swap(char *a, char *b); What would happen when you call it? It would create … | |
Re: On line 6 ICommDlgBrowser3 : public ICommDlgBrowser2 Your compiler can't find a definition of ICommDlgBrowser2 Did you include the proper header file? | |
I have a simple question about objects and exception handling. What happens to an object after its thrown? Does the implementation take of cleaning up that object or should I be aware of any situations that may require extra care...I've read this from - Inside The C++ Object Model by … | |
Re: Because that's what the function does..Here's a quote from my help file "int putchar(int c); writes the character c, cast to an unsigned char, to stream" | |
| |
Re: When you enter a character from the console you hit return as well so you really enter two characters..e.g Enter the character 'a' plus return yeilds 'a', '\n' Instead of using putchar() try using fprintf(stdout, "value->%d\n", t); fprintf(stdout, "value->%d\n", x); What values were displayed? | |
Re: Well what's it supposed to do? Can you give us an example of how its failing? Oh by the way, don't use fflush(stdin) its behavior is undefined. | |
Re: I don't like that your realloc'ing ch1 and then incrementing the pointer ch1. To me this seems like a recipe for disaster | |
Re: Try removing the () in if ((textBox1->Text == ("")) && so that its is if ((textBox1->Text == "") && Actually on further inspection, you have on line 3 (radioButton3->Checked = false) it should be (radioButton3->Checked == false) |
The End.