15,300 Posted Topics
Re: Is there something wrong with the code? You don't need to call endl but rather do like this: [icode]cout << a << "\n\n";[/icode] | |
Re: There is no one place. For *nix its normally the man pages. You can access them by googling "man function_name". For MS-Windows it would be MSDN. You can also just google for the c++ container class, e.g. fstream. If you want the absolute authority then you will have to BUY … | |
Re: Try a little redesign of the program by removing all those static objects and pass them by reference into the functions, such as [icode]void load_character(Character& ret)[/icode] Your program will use less memory that way too. | |
Re: lines 8 and 9 [code] int i, max_val; double x[max_val]; [/code] What is the value of max_val? What is the size of array x? | |
Re: character arrays that are created on the stack like iReturn[] can not be returned because they are destroyed as soon as the function returns. You have two options 1) Have the calling function create the array and pass it to GetBase2() as a parameter, such as [icode]char* GetBase2(int iBase, int … | |
Re: 1. exec gives you a lot more control, look in the man pages or use google and you will find all the different ways exec can be used. 2. Either redirect the output such as [icode]system("data >filename.txt")[/icode] to a file or use pipes. 3. Why not? For each fork() you … | |
Re: Look at the function kbhit() in conio.h, which is non-standard and not supported by all compilers. | |
Re: Odd -- I could have sworn that this problem as asked and solved over a week ago. | |
Re: Number of iterations? Infinite. Why? because 1/2 = 0 (integer division) so the value of x will never change. | |
Re: You have made that problem a lot more difficult than it needed to be. [code] int compare(const void *x,const void *y) { return(* ((int*)x)-*((int *)y)); } int qsortselect(int keys[], int n, int size) { qsort(keys,n,sizeof(int),compare); int x = keys[size]; return x; } int main() { int A[5]={3,5,67, 7, 2}; for(int … | |
Re: [QUOTE=Adak;1178002] [CODE] int count[101] = { 0 }; //assign all elements to zero value if (your char is a number from 1 to 100) count[char + '0']++; //remember count[0] will not be used here. [/CODE][/quote] Your example is just a little bit wrong. The file contains integers, so if they … | |
Re: strcmp() is case sensitive, meaning that the word "Hello" is not the same as the word "hello". Maybe that is what is going on with that program. Try using a case in-sensitive comparison, such as stricmp(). The same function might be called something else on g++ compiler, such as comparenocase(), … | |
Re: >>void print_hello(int n, int *) What is that second parameter for? All that is doing is printing one line of * below the text. What about above the text and on each side? [quote] **************** ** Hello World *** **************** [/quote] This is how to do it [list=1] [*]Print the … | |
Re: What the hell makes you think I'm going to do your work for you? I have my own to do. | |
Re: >>/N=7 2^N=128 That is bytes, not bits (see [URL="http://groups.csail.mit.edu/cag/ps3/cell_pointers.shtml"]this link[/URL]). 128 bits is 16 bytes on computers where 1 byte is 8 bits. | |
Re: I never create a pointer to a vector -- pointer here is just not necessary. Your third example is the most common way to do it. | |
Re: >>static long count; >>count++; Your program is incrementing an uninitialized integer and then you use that integer later on in the function. initialize it to 0 [icode]static long count = 0;[/icode] | |
Re: You need to add a constructor to Rectangle that takes no parameters -- that's called the default constructor. | |
Re: Its not possible in any language. Files don't know a thing about fonts. As for Notepad.exe I know of no way to change it from a c program. | |
Re: >>but don't kn0w how t0 apply it for 3 c0nditions ? Is the o key broken on your keyboard? [icode]if( a > b) ? a : if( b > c) ? b : c;[/icode] You could in theory just keep going on an on like that, but it will just … | |
Re: I found setjmp and longjmp quite useful in database programs to quickly return errors between deeply nested function calls. c++ exceptions are the alternative in c++ programs. goto is only useful within the same function. setjmp and longjmp are between functions, although could be used within the same function too. | |
Re: If you used c++ <vector> class you would not have to worry about it because that class will do all the expanding for you. But if this is homework then you may or may not have that choice. | |
Re: >>Can someone help me with this???? Help you with what? We don't do homework for you -- that's your job as a student. | |
Re: >>s this code portable between operating systems No. Works only on MS-Windows because it appears to be using win32 api functions. There is no portable way to do what you want using any standard C or C++ functions. There are non-standard functions, such as ncurses which I know has been … | |
Re: The four bytes before the beginning of the BSTR is the number of bytes allocated to the BSTR, which may or may not be the length of the string. In fact the BSTR need not contain a null-terminated string at all (either UNICODE or ascii). It could contain binary data … | |
Re: >> //NOPE! Doesn't add 1st digit... because it's stuck in 'ch' b/c of inFile.get(); call inFile.unget() to put the digit back onto the stream. | |
Re: Start out by posting in Game Development forum. How well do you know c language? Or any other programming language ? | |
Re: Those are called [b]function prototypes[/b] and they don't go in main(). Put them near the top of the program unit, after all includes. Alternatively, you can create your own header file and put them there. [code] #include <iostream> #include <string> // other includes here int score_num(int& ns1,int& ns2,int& ns3, int& … | |
Re: The square root of a negative number is an imaginary number. sqrt(-1) is not -1. To confirm this, see [URL="http://www.csgnetwork.com/squarerootsquarecalc.html"]this calculator[/URL] | |
Re: There are several ways to solve that problem. IMHO this is the simplest. sprintf() is your friend here [code] char filename[255]; // final file name char* namePt1 = "Labyrinth"; int num = 5; sprintf(filename,"%s%d.txt", namePt1,num); ofstream fileLabyrinth(filename); [/code] Alternate method is pure c++ [code] string filename; string namePt1 = "Labyrinth"; … | |
Re: I agree with your teacher. TurboC is very ancient. Did your teacher suggest a compiler? If not, there are several of them you can use Code::Blocks with MinGW compiler VC++ 2008 Express just google for those names and you will find their download links. But what does that have to … | |
Re: Don't do that even if you would. The macro is too large and will greatly increase the size of the final program. Just write a normal function that takes variable arguments. | |
Re: The functions isalpha() and isupper() will tell you whether the character is an upper-case character or not [code] for(int i = 0; i < userInput.length(); i++) { if( isalpha(userInput[i]) && isupper(userInput[i]) ) count++; } [/code] | |
Re: 1. Because they said so. Why would you want to comment out the comments? If you want to comment out a large block of code that may contain comments, then there are other ways to do it. I do it like this. [code] #if 0 // code here #endif [/code] … | |
Re: What problem(s) are you having? You can't take your car to a repairman and tell him "my car is broke please fix it". | |
| |
Re: Please stop putting your questions in quote tags -- it just makes your posts confusing to read/understand. | |
Re: Why would you want to make it [b]void[/b]? [code] double** foo(int rows, int cols) { double ** ptr = malloc(rows * sizeof(double *)); <snip> return ptr; } [/code] | |
Re: I've seen "report bad posts" forums that on other web sites too, but the way DaniWeb does it is a lot easier. We don't have to copy/paste a link into another forum to report it. Hitting the Flag Bad Post link does it all :) | |
Re: [URL="http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc09lc.htm"]Read this link[/URL]. [quote]In order for the compiler to produce meaningful references to line numbers in preprocessed source, the preprocessor inserts #line directives where necessary (for example, at the beginning and after the end of included text). [/quote] When the preprocessor parses your *.c program it will create a *.i … | |
Re: If you have time (within 30 minutes of the original post) just remove all the text and write "<deleted>" or something like that, then PM one of the mods who MIGHT delete it. | |
Re: Depends on the file's contents. As a general rule of thumb, just open the file as a normal text file and read its contents one line at a time. Beyond that, you will have to tell us what's in the file. | |
Re: >>How can I terminate a server after some number of connections Put [icode]exit(0);[/icode] after the loop ends on line 21. | |
Re: One way to do that is to create a structure that contains the strings and an integer [code] struct words { char* word; int count; }; [/code] Now make a simple array of these structures and initialize all counts to 0 and character arrays to the words in the list … | |
Re: [QUOTE=COKEDUDE;1173363]I thought since you need [ICODE]#include <ctype.h>[/ICODE] for [ICODE]tolower()[/ICODE] it is not standard. Why would you have to include [ICODE]#include <ctype.h>[/ICODE] if it is a standard function?[/QUOTE] All functions have to be declared before they can be used, whether they are standard C functions or not. Standard functions are not … | |
Re: Read [URL="http://winprog.org/tutorial/"]this tutorial[/URL]. It has a section about menus and other resources. | |
Re: change the structure to use std::string instead of the char data. Then change the insert function to get a string from the keyboard instead of a single character. You will probably need to make other appropriate changes to your program as well. | |
Re: The solution is pretty easy if you think about it. Every character in the English alphabet, and other characters too, have a numeric value between 0 and 255. To see what they are just google for "ascii chart". Given that, create an int array of 255 elements and initialize all … |
The End.