556 Posted Topics
Re: It only appears to work, it is in fact undefined behaviour, this is exactly what it says the behaviour may be a crash or it may appear to work or anything inbetween and it may do different things every time it is run. If you put this sort of code … | |
Re: Line 43: you ask the user for a string but the variable str is only a single character not a string (an array of char) Your 2 arrays alpha and ALPHA seem unlikely, at this stage to be of any use. Your encrypt function just needs to read everry letter … | |
Re: Your problem is in the while loop at line 9. The thing is that cin is always going to return ok (true) while it can perform the operation you have requested so the only way to break this loop is to input data that can't be converted to a number, … | |
Re: Your syntax on line 7 is never going to work, it could only ever work is C was an acester of A. But you can initialise a class in its constructor from another class like this class C { public: explicit C(const A& inita) : a (inita) { } private: … | |
Re: At line 107 you are missing the const on the declaration of the inclass parameter Your declaration and definition of list_clear at lines 28 and 55 do not match | |
Re: > function/macro sizeof(p1) sizeof is not a function or a macro it is an operator. | |
Re: Also it's not really overloading, if you put both into a single program you would get an error, it has to be one or the other. True overloading, like C++ would allow both function definitions to co-exist, if this where not main. C++ also does not allow overloading of main … | |
Re: You have a couple of options. 1. Read the whole line using getline into a std::string and use the various members of std::string to parse the line into the individual data members of your structure 2. Use the delimiter parameter of getline to read up to the ; delimiter in … | |
Re: You have defined the TPhysics constructor at both line 32 and 52 | |
Re: This sounds like it is a porblem caused by putting locks inside a loop without putting in anything that holds them up. The thread reading from the socket should be held up by the socket comms, that is while it is not receiving any data it should not be trying … | |
Re: I feel that someone should point out that having public member variables is generally very poor practice. The coding standards at my work require all member variables to be private. | |
Re: In the first program you wanted each recursion to output a result where as in the second recursion you just wanted the result of the whole recursion. You have no output (cout) calls in your recursion in either case; this does not matter for the second program as you only … | |
Re: A simple page request from a browser looks something like GET /example.html HTTP/1.1 Host: www.example.com (actually with an extra newline at the end of it but the code parser on this site wont show it.) At line 68 - 74 of your code you make no attempt to parse this … | |
Re: Does database.txt use '\n' as end of line characters? Does database.txt have a '\n' on the last line in the file? | |
Re: Line 11: Undefined behaviour: you call strlen on an unititialised string, this could easily lead to memory accesses outside the boundaries of the array string. May be you meant to do this after string is requested from the user. Line 13: Format string error: %c tells scanf to get a … | |
Re: Of course the way the function min is written it is very likely not to work, cause a segfault even because it accesses the 1000th element of an array of size 6. | |
Re: You have used more loops than is necassary. The thing is once you have chosen a value of a and b you can calculate the value of c that solves the equation 2a + b - c = y. You do not need a loop that checks every value of … | |
Re: What you should do is 1 Not free the data at line 31, you can not know that the thread has not finished with it. Test by adding a short sleep in print_thread_id Then either 2 Use pthread_join to detect when the thread has finished running then free the memory. … | |
Re: This is strickingly similar to the last posts of [this thread](http://www.daniweb.com/software-development/cpp/threads/448226/assembly) yet somehow a different username. Check there for an answer. | |
Re: Looks like A QTableWidget automatically deteles any cell widgets you set. That means that for each of the 3 cell widgets you set it will try to delete the widget individually. However you did not individually allocate those widgets, you allocated an array of widgets, that means that for 1 … | |
Re: That is because in main you pass an initial value for count to check_birthdays but you do not initialise the value you pass. This is actually undefined behaviour. A quick fix is to initialise the variable count in main (to 0) or to call check_birthdays as `check_birthdays (birthdays, people);` thereby … | |
Re: size_t is not terribly complicated, I think you are probably reading more into it than there is. size_t is defined in the standard as "the unsigned integer type of the result of the sizeof operator" And that is basically it, it is an unsigned integer type. It is the type … | |
Re: 1. getMonth and getDay both need to be const methods they are called through const references in operator== 2. daysInMonth doesn't return a value for all input values 3. daysInMonth is missing a Birthday:: from its definition 4. You have some comparisons between signed and unsigned integers | |
Re: I imagine this is an endian issue. When storing an integer in memory little endian processors store least significant byte first, big endian processors store most significant byte first. So the numbers are stored in memory as follows 30030 little endian machine: 4E 75 00 00 big endian machine: 00 … | |
Re: How about you show us the relavent code lines and the full compiler output. | |
Re: result2 and fileUser are both std::string, therefore the will match if the have exactly the same characters in them, same characters same order same case. If they don't match then they don't have exactly the same strings in them. This is your real question, why do result2 and fileUsernever contain … | |
Re: Line 24 is wrong, `x%x` is always 0 and `x%1` is also always 0 so it is the equivilent of if (0 == 0 && 0 == x) Calculating is a number is prime is not trivial (except for the first few) and I would suggest that you use a … | |
Re: I believe you have misunderstood how setw works. setw sets the minimum width of the next field; if the field length is less than the set field width then the field is padded with spaces (or the given padding character) either to the left or right of the data until … | |
Re: A C string is and array of char. It is zero terminated, that is the last char in the string (but not necessarily the array) is the ASCII nul or '\0' or plain 0 (different names for the same thing). All characters up to the zero terminator must be printable … | |
Re: Just read it into an integer. std::string operation; int operand; cin >> operation >> operand; // verify cin is good (i.e. no input errors occured //lookup operation and call it with operand. | |
Re: To start with `scanf("%s",&sh);` is incorrect it should be `scanf("%s",sh);` because sh is an array so using it without any [] already produces a pointer to it, you don't need to de-reference it. Secondly, never, ever use `gets`, always use `fgets`, so not `gets(sh);` but `fgets(sh, sizeof sh, stdin);` it … | |
![]() | Re: The bar only seems to be appearing when you are looking at a thread, for me it disappears when I am looking at a forum thread list which is a fairly ittitating feature in a navigation bar. ![]() |
Re: <pedantic> Not time of day, number of seconds since the epoch passed so you get a different seed every time (as long as you don't manage to seed your PRNG twice with-in 1 second). </pedantic> | |
Re: You can't talk about 'the best' compiler, you would have to give some context, for example MSVC++ is probably the 'best' compiler if you want to create MFC programs (not that I think anyone should want to do that), on the other hand for a long time if you were … | |
Re: At line 5 you have `char* comandi[n];` but at this point n is not initialised so even if you are using C99 (as opposed to C89/C90 which doesn't allow variable length arrays) this line of code can not go well. Change the `n` for a `10` and everything works. You … | |
Re: Actually while what sepp2k says is generally true for many many platforms it is not absolutely true it rather depends on the platform's hardware and how it does addressing. For example I worked with a microprocessor that used 16bit word addressing, that is each 16 bit address gave the location … | |
Re: It entirely depends on the format of the file you wish to read. For example a WAV file is store as a series of samples, no special library is required to read it just read the binary data. On the other hand an mp3 file is encoded using the MPEG … | |
Re: Line 14 you declare ptr as a `record *`, line 27 the function display takes as a parameter `record *[]` which is equivilent to `record **`. I am surprised that you did not get a compiler warning or error. Correct the type that the function display takes as a parameter … | |
![]() | Re: I would say that, particularly in portable code, the C bitfield syntax is of no use. It is a syntactic sugar for accessing bits in an integer type that can easily be achieved using the bitwise operators (& | ~ << >>) the difference is that while using the bitwise … |
Re: You have tried to declare all your functions inside main. You can not declare functions inside functions and while you can declare classes inside functions you probably don't want to here because then the class wont be visible to any other functions. You code layout should have this structure #include … | |
Re: > [condition] ? [statement1] : [statement2]; Strictly it is `[expression1] ? [expression2] : [expression3];` There are no such things as conditions in C only `expressions` and `statements`. `Statements` are not required to return a value but `expressions` are. `expression2` is evaluated if `expression1` evaulates to true (any non-zero number) otherwise … | |
Re: Correct C#Jaap, the logical and (&&) and or (||) operators use shortcut evaluation, that is if they can determin the result after evaluating the left hand expression they do not bother evaulating the right hand expression. For && this means if the left hand expression is false the right hand … | |
Re: strlen and sizeof should always return different values because strlen never includes the trailing '\0'. In a compleatly normal string such as `"Hello World"` with no embedded terminators `strlen` will return a value 1 less than `sizeof` returns. It they don't return different values you have a buffer overrun in … | |
Re: OK you have a mutex to protect access to you data in the threads but you do not use it when access the data in main. This is an error whenever you access the data even for read you should always lock the mutex protecting its access. It might be … | |
Re: Which means if you added the switchs `-Wall -pedantic` to your compiler command you code would not compile (try and see) * **-Wall** - output all warnings and errors (actually not quite all a few esoteric ones still need to be explicitly enabled if you want them) * **-pedantic** - … | |
Re: >int a[10][10]; > > is same as, > >int(*a)[10]; Err, NO. The first, a is an array of 10 arrays of 10 integers. The second a is a pointer to an array of 10 integers. Assuming the first, `int a[10][10];`, then the expression `a` evaulates to a type `int(*)[10];`. Which … | |
![]() | Re: Yes that's pretty much it. Good practice would be to treat something that has been declared as const as const. On most of the embedded platforms I have programmed on anything declared const was put into read only memory so assignments wouldn't have worked, you can never be 100% sure … ![]() |
![]() | Re: You have multiple problems but most of them stem from lines 10 and 16. At line 16 you have detected that you have an end condition but rather than return an end condition flag you return the same value as you leaf condition at line 6. If your end condition … ![]() |
![]() | Re: You haven't got 1 quite right, arr is not "a pointer to an array of 2 elements in which each element is a pointer to a 2-D array" but rather the expression `arr` evaluates to a pointer to the first element in an array of 2 elements in which each … ![]() |
The End.