1,174 Posted Topics
Re: Try asserting your indices (everywhere) .. [CODE] #include <assert.h> while ( i < m ) { for (j=0;j<in;j++,l++,i++) { /* rows and cols are your allocated dimensions ... */ assert(k >= 0 && k < rows); assert(l >= 0 && l < cols); a[k][l]=i; } [/CODE] | |
Re: >> My rand() isn't very random. As a matter of fact, it's not random at all! >> I get the same result every time on both computers: 180428383 This is by design, you want to [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/srand/"]Initialize random number generator[/URL]. | |
Re: >> How should I initiate the str_month, I thought that line #12 initiation is sufficient [URL="http://www.cplusplus.com/reference/clibrary/cstring/strncpy/"]strncpy()[/URL] does not necessarily NULL-terminate the string -- so, you might do e.g. .. [code] str_month[3] = '\0'; [/code] | |
Re: >> But when I am trying to pass this value to my struct and then to print it it does not work. You have forgotten the [ICODE]%s[/ICODE] format specifier, so .. [CODE] strcpy( myaccounts->allaccounts[myaccounts->pos].name,name); /* %s embedded in the format string */ printf("Name = %s\n",myaccounts->allaccounts[myaccounts->pos].name); [/CODE] >> And another question … | |
Re: >> ... tokenize my string, which is read from a file, but my output is blank, why? There could be many reasons for no output at all - was the file opened, what's in it etc. You could get a bit creative and display what you read from the file … | |
Re: >> Why doesn't it accept the filename I give it? [URL="http://www.cplusplus.com/reference/iostream/fstream/open/"]open()[/URL] only accepts a [ICODE]const char *[/ICODE], so you have to use [ICODE]c_str()[/ICODE] .. [code] file.open(filename.c_str()); [/code] In your original post, you are calling [ICODE]main()[/ICODE] recursively - it's a poor practice and also forbidden. You could instead devise a regular … | |
Re: The code you've posted seems to be OK, so if the problem still persists, go ahead and post all of the code. | |
Re: >> 'ofstream': No such file or directory": The C++ header files are listed in this [URL="http://www.cplusplus.com/reference/"]Reference[/URL]. | |
Re: You might go through a [URL="http://www.newty.de/fpt/fpt.html"]function pointer tutorial[/URL]. | |
Re: [QUOTE=lais90]my os is windows 7, and I think it is support conio.h So how could I use conio.h to edit my color?[/QUOTE] Even if your compiler has <conio.h> in some form or another, I doubt you'll find anything like you want in it. Hence I'd suggest that you forget about … | |
Re: >> a error message is triggered which says "The operation completed successfully." This happens because you are using [ICODE]FormatMessage()[/ICODE] incorrectly. See [URL="http://msdn.microsoft.com/en-us/library/ms680582%28v=VS.85%29.aspx"]Retrieving the Last-Error Code[/URL]. Note how the value returned by [ICODE]GetLastError()[/ICODE] is passed to [ICODE]FormatMessage()[/ICODE]. | |
Re: @namasee: You must have missed the Daniweb Rules .. [QUOTE=DaniWeb Rules] Keep it Clear * Do post in full-sentence English [/QUOTE] About the books, there is a lengthy sticky thread --> [URL="http://www.daniweb.com/forums/thread70096.html"]C++ Books[/URL] | |
Re: "Selected" is initially an uninitialized pointer (read: it is [I]garbage[/I]). Unless it gets assigned inside the loops, [ICODE]ValidMove()[/ICODE] receives garbage. I think that instead of assuming that everything works as you think it should, you should verify that this actually is the case here, so how about ... [code] void … | |
Re: [QUOTE=hermann87;1117788] I've added the .lib and header files under Project->Linker Dependencies and Project and Solutions->VC++ Directories (where I added library files for x64 and header files) but still nothing.[/QUOTE] As far as I know Visual Studio 2008 [B]Express[/B] Edition does not support 64-bit programs. However, by installing the correct Windows … | |
Re: One more issue not yet mentioned, please the comments .. [code] void GeneticAlgorithm::RouletteWheelSelection() { int iRandomNumber, iTotalFitness; CalculateTotalFitness(iTotalFitness); CreatePie(); for(unsigned long int i=0; i<m_iPopDensity; i++) { GenerateRandomNumber(iTotalFitness, iRandomNumber); for(unsigned long int j=m_iPopDensity - 1; j >= 0; j) { if(iRandomNumber > m_vPopulation2[j]->m_iCumulativeFitness) // Assuming j == 0 here ... j--; … | |
Re: [QUOTE=triumphost;1165712]I have a button caption, i know its a button and i have its handle...[/QUOTE] Are you sure about that? [ICODE]FindWindowxx()[/ICODE] may very well return NULL. So, first thing to do, would be to add code that checks that you actually receive handles to those windows. Upon failure, you may … | |
Re: >> .. my head is just spinning If the libraries seem daunting, you might check out a basic MSDN CryptoAPI example [URL="http://msdn.microsoft.com/en-us/library/aa382380%28v=VS.85%29.aspx"]Creating an MD5 Hash from File Content[/URL]. | |
Re: >> float CDROM::ReturnCost(void) [COLOR="Red"]const' : overloaded[/COLOR] member function [COLOR="Red"]not found[/COLOR] in 'CDROM' It's saying that the function declaration/definition signatures are not matching wrt. your [ICODE]const[/ICODE] usage, so you want to have .. [code] class CDROM { ... float ReturnCost() const; // <--- const was missing // The same thing for … | |
Re: The code has been compiled with a compiler that supports variable length arrays, Microsoft's C compiler does not and probably never will support that feature. You can work around this with a simple [ICODE]#define[/ICODE], like so [code] #define NAME_OF_YOUR_CHOICE_HERE 8192 /* int n = 8192; */ ... int main() { … | |
Re: In your code the following cast is [COLOR="Red"]wrong[/COLOR] [code] for (j=0; j<BYTES; j++) printf("[%02X]\n", (const unsigned char [COLOR="Red"]*[/COLOR]) data[j]); [/code] Could you post the complete compilable code which demonstrates the working and non-working behaviour. I think your problem eventually relates to the default [ICODE]char[/ICODE] being signed. | |
Re: In addition to what nezachem stated, it looks like you are also simply exploding the stack with your buffer declaration [code] char buffer [INT_MAX]; [/code] | |
Re: Basically you are pushing the left-hand side of the string onto the stack and then comparing that data with the very same left-hand side of the string. The right-hand side of the string is not involved in the comparisons. | |
Re: [URL="http://en.wikipedia.org/wiki/Man_pages"]man pages[/URL] might be worth a try. | |
Re: >> output becomes full of INF INF INF 100 times :-) You have to initialize the [ICODE]sum_*[/ICODE] variables. | |
Re: It looks like it ought to work as such. However, you could check that; [LIST] [*] You have the [ICODE]ON_WM_TIMER()[/ICODE] macro in the dialog class' message map. [*] [ICODE]SetTimer()[/ICODE] succeeds (returns a nonzero value). [*] [ICODE]UpdateData()[/ICODE] succeeds (returns a nonzero value). [/LIST] | |
Re: Though I might be missing something here, but anyhow, I think changing the comparison functions to [icode]static[/icode] would be in order here, so you'd have: [code] static bool Descending(const pair<const T, int> &, const pair<const T, int> &); sort(mode.begin(), mode.end(), &Statistics::Stats<T>::Descending); [/code] P.S. Why the [icode]const[/icode] in the vector declaration … | |
Re: >> RNInterpreter.C:8: note: (perhaps a semicolon is missing after the definition of ‘Thousand’) Your compiler is suggesting that Thousand.h looks like [code] class Thousand { // All your Thousand stuff here ... } // <--- ... but no ending semicolon after the curly bracket [/code] | |
Re: You want [code] m_strLine.Replace("\n", "\r\n"); [/code] >> m_strLine.Replace ( '\n' , [COLOR="Red"]'\r\n'[/COLOR] ); [COLOR="red"]That[/COLOR] should give you a warning or two, are you ignoring compiler warnings? | |
Re: >> it also displays the two parent directories, '.' and '..'. Line #30 stores both "." and ".." in addition to the directory and file names, so you have to work around that. | |
Re: If you are on Windows, then look into [URL="http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx"]FindFirstFile()[/URL]. As the documentation states, you can use wildcards in the file/path name, e.g. "c:\\foo\\bar\\*.txt". | |
Re: >> when I type 'q' into the command line it should enter that if statement, but it doesn't. [icode]fgets()[/icode] stores the newline in the buffer, whenever there's enough room to do that. So, you are actually comparing [icode]strcmp("q", "q\n")[/icode], which apparently returns non-zero. You might use e.g. [URL="http://www.cplusplus.com/reference/clibrary/cstring/strcspn/"]strcspn()[/URL] to get … | |
Re: >> regarding latest c std You might be interested in [URL="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf"]the latest draft[/URL] Perhaps also see [URL="http://www.open-std.org/jtc1/sc22/wg14/www/standards"]C - Approved standards[/URL] | |
Re: >> Now I'll work on the fibonacci function. You need to initialize [icode]j[/icode] before using it - since it's an automatic variable, it is NOT initialized to zero by the compiler. | |
Re: You are probably just doing something wrong or having a configuration issue. You might refer to Eclipse's Help and/or post in a dedicated [URL="http://www.eclipse.org/forums/index.php?t=i&cat=6&S=3fdffc50ca1404220a8bbc1ecbd4eb13"]Eclipse forum[/URL]. | |
Re: >> searching does not work pls help You should be much more specific as to what is not working. You might read Narue's [URL="http://www.daniweb.com/forums/thread78223.html"]Read This Before Posting[/URL] - especially the section [B]Describe your problem clearly and fully![/B]. | |
Re: Maybe I'm misunderstanding the problem .. but if not, then you might store the points clicked in a container (e.g. vector<point>). So that upon drawing, you iterate over the container, drawing every point stored thus far. | |
Re: Apparently you are accessing memory to which you have read-access. Generally, there are no built-in safety nets with regards to e.g. reading/writing out of array bounds and other things alike - you just have to be careful. | |
Re: If you have MS Word, then open the document in Word and do a Find/Replace, replace two adjacent spaces with a single space. | |
Re: >> how can get path of specified exe file? What does [I]specified[/I] mean here? If you need to know the path of your running program, then use [URL="http://msdn.microsoft.com/en-us/library/ms683197%28VS.85%29.aspx"]GetModuleFileName()[/URL]. | |
Re: I think it goes along the lines of .. [code] // Get current style LONG dwStyle = GetWindowLong(hWnd, GWL_STYLE); // Drop WS_SYSMENU dwStyle &= ~WS_SYSMENU; // Apply current style SetWindowLong(hWnd, GWL_STYLE, dwStyle); [/code] and immediately after that, use [URL="http://msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx"]SetWindowPos()[/URL] speficying the SWP_FRAMECHANGED flag. Although, note that this also gets rid … | |
Re: [QUOTE=N1GHTS][b]Person person = *p1;[/b] This is copying the pointer address to the first 4 bytes of [b]firstName[/b] in the newly created instance of [b]Person[/b], and then completely undone by line 27: [/QUOTE] Sorry, but that is actually not so. [b]Person person = *p1;[/b] does a struct assignment, i.e. copying [icode]sizeof(Person)[/icode] … | |
Re: See GetPrivateProfilexxxxxx()/WritePrivateProfilexxxxxx() functions in [URL="http://msdn.microsoft.com/en-us/library/ms724875%28v=VS.85%29.aspx"]MSDN[/URL] | |
Re: >> problem is getting the filename from the switch function back into the main In order to do that, you need to pass in the address of the pointer (filename) that you will be setting inside this setup() function. C [I]passes arguments by value[/I], i.e. generally arguments passed to a … | |
Re: In your first case, [icode]pDerived[/icode] ends up being a NULL pointer. When you call [icode]TestD()[/icode] through it, the [I]this[/I] pointer will also be NULL (inside [icode]TestD()[/icode]) - hence the crash. In the latter case, you are trashing memory worth of two ints approximately where your allocated Base object is stored … | |
Re: Line 40 is wrong, what happens there when [icode]i == 0[/icode]? | |
Re: Don't set [icode]m_pMainWnd[/icode] to point to the dialog object, because during the execution of [icode]DoModal()[/icode], MFC does a [icode]PostQuitMessage()[/icode] via the dialog's [icode]OnNcDestroy()[/icode] (if [icode]m_pMainWnd[/icode] points to the window being destructed). So, the program terminates as soon as the posted [icode]WM_QUIT[/icode] gets extracted from the message queue, even though you've … | |
Re: >> i am not receiving any output i pressed ctrl+f9 If you are saying that CodeLite actually fails to run the compiler altogether, then it's probably best to post in [URL="http://www.codelite.org/forum/viewforum.php?f=3"]CodeLite forum[/URL]. | |
Re: >> The last output to the screen is the prompt to enter the name of the output file. Once you've gotten out of the initial while() loop, I believe you use Ctrl+Z to stop entering coordinates, [icode]cin[/icode] has eof bit set, which you must [URL="http://www.cplusplus.com/reference/iostream/ios/clear/"]clear()[/URL] before trying to get any … | |
Re: [icode]dynamic_cast<CTriangle*>(ppoly1)[/icode] gives you a NULL pointer, through which the call gets made. If you were to modify the (non-existent) object's state inside the [icode]triFunc()[/icode], then you would get a run-time error, but because you just return the constant value (5), it appears to 'work'. | |
Re: >> How do I check if a member of a struct is null? Just like you are doing, i.e. [CODE] // Is it a NULL pointer? if(ErrorInfo->TestName != NULL) { // No it isn't ... } [/CODE] >> debug shows it as 0xccccccc, "") This value [icode]0xccccccc[/icode] tells you that … |
The End.