344 Posted Topics
Re: Fix: line 19, flase should be false line 32, should be lo = mid; line 49, should be }while(toupper(reply) == 'Y'); | |
Re: Exactly as Bob suggested, just fill in the blanks. void Reverse(char entry[ ], int length) { if (0 == length) // if (!length) return; char *front = &entry[0]; char *rear = &entry[length - 1]; char temp; while (front < rear) { // swap front/rear // increment front ptr, decrement rear … | |
Re: 1. Define what a 'simple project' is. 2. Once you've established what your project should do, I'm sure Googling would present you with many ideas and types of algorithm. | |
Re: Have a look from lines 13 to 16, you're writing beyond the bounds of the allocated array. | |
Re: This should work. bool Backup::runBackup(std::string source, std::string dest) { char destPath[MAX_PATH] = {0}; char sourcePath[MAX_PATH] = {0}; // Note: source and destination paths must be double null terminated errno_t error = strcpy_s(destPath, dest.c_str() ); if (0 != error) { // handle error return FALSE; } error = strcpy_s(sourcePath, source.c_str() ); … | |
Re: I'll get you started with a function skeleton - show what code you come up with if you have problems. int multiple(int first, int second) { // fill in the blanks // how do you determine whether first divided by second gives a remainder of zero? } | |
Re: Commented where I thought necessary - untested /*program to find a number in the range 1 to 100 that has the largest number of distinct divisors*/ #include <stdio.h> #include <stdlib.h> int main() { //note: excludes divisors of 1 and the number itself int countstore[101] = {0}; int result, i, num, … | |
![]() | Re: In line 18 you haven't defined the operator. Try friend ostream &operator<<(ostream &mystream, Circle &c); |
Re: Post your code, my crystal ball is away being polished. | |
Re: @kshivap http://msdn.microsoft.com/en-us/library/czcad93k | |
Re: > How can I eliminate the "high, reserved byte" or ensure it is set to 0? color = GetPixel(hdc_, 10, 10) & 0xFFFFFF; | |
Re: To generate integers between 10 and 40 inclusive you can use: rand()%31 + 10; By N DISTINCT random integers, I assume that it means N different integers. So you'd have an array[N] and keep generating random range numbers, check if they're already present in the array and if not place … | |
Re: Here's an implementation of your algorithm in c++. int BestSquareMatch(int i) { if (i == 0) return 0; if (i < 0) return -1; // error undefined int match = i/2; while (pow(static_cast<double>(match), 2) > i) { --match; } //increment to the last integer that satisfied the condition return ++match; … | |
Re: I just threw this together. It will move all zero values to the end of the array. Hope it helps. int iarr[] = {1, 3, 0, 0, 5, 7, 0, 0, 0, 9, 9, 6, 0}; int len = sizeof(iarr)/sizeof(iarr[0]); int i , j, idx; for (idx = 0; idx … | |
Re: As well as pyTony's suggestion, in lines 12 and 13 you are trying to open the same file twice. | |
Re: From line 31: float max = 0; for (u = 1; u <= c; u ++) { if (max < input[u]) { max = input[u]; c = u; // ** means that c is updated to u, hence the loop will break, so discard this line. } } Also you … | |
Re: It makes no sense to implement this as a 'for' loop, because the number of loops will vary depending on the integer you wish to reverse. This will work, but it really seems pointless: int x = 123456; int y = 0; for (int j = 0; ; j++ > … | |
Re: printf("factorial of (%d) = %d\n", fact, result); printf("press Enter to exit\n"; getchar(); return (EXIT_SUCCESS); or do you mean: #include <stdio.h> #include <stdlib.h> #define fact 5 int main(void) { int i, j, result; int _fact = fact; for (j = 0; j < fact; j++, _fact--) { result = 1; for … | |
Re: 1. Remove (LPBYTE) from CreateFileMapping(...) 2. I'm guessing that you're wanting to do something with the mapped file, in which case you'd have: fileView = (LPBYTE)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); | |
Re: Post the code that you written so far and describe which parts you're having problems with. You won't receive any help at this forum until you actually make a fair attempt to code your assignment. | |
Re: I'm not 100% sure I understand the question, but this seems OK and avoids any crashes. #include <iostream> using namespace std; int main() { int A[10][10], row, column; for (row = 0; row < 10; ++row) { for (column = 0; column < 10; ++column) { // avoid divide by … | |
Re: Check out [IsZoomed](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633531%28v=vs.85%29.aspx) function. | |
Re: a more compact example , with some modifications. #include <iostream> #include <string> #include <ctime> void setSecretCode(char*); using namespace std; int main() { char code[5]= {0}; setSecretCode(code); cout << string(code) << endl; cout << "press Enter to exit..."; cin.get(); return 0; } void setSecretCode (char* code) { string colors = "RGBYO"; … | |
Re: Did you set the value of y to 1 before entering the do/while loop? Also you have: if (y >= 1 && y <= 4) as far as I can see y would always be greater than or equal to 1, so there's no need to test that condition. | |
Re: [These tutorials](http://www.opferman.com/Tutorials/) should cover what you need to know. | |
Re: You could also use - void TransformUppercase(std::string& s) { std::transform( s.begin(), s.end(), s.begin(), ((int(*)(int))std::toupper)); return; } | |
Re: You can start by reading the following: http://www.cplusplus.com/reference/iostream/ofstream/open/ http://www.cplusplus.com/reference/iostream/ifstream/open/ | |
Re: Though your code is not strictly c++, this cuts down on some unneeded code. int** PntrFunc(int** itemGiven) { **itemGiven += 500; return itemGiven; } int main() { int * pntr = new int; *pntr = 50; int ** mPntr = PntrFunc(&pntr); printf("result %d\n", **mPntr); delete pntr; "press Enter to exit\n"; … | |
Re: The recursive call to main() at line 71 is not a very good idea. You'd be better off using a do/while loop. do { // main code body std::cin >> cont; } while (cont != 'y' || cont != 'Y'); return 0; | |
Re: Just taking the first part of the equation - 3x^3 To multiply you need to use * as in 3*x ^ is bitwise xor, do you really want to calculate 3 times x xor 3? | |
Re: An example with no error checking or optimization. void squeeze (char c, char S[]) { int i = 0; int j = 0; char fwd[MAX]; memset(fwd, 0, MAX); for ( i; i < MAX; i++) { if ( S[i] != c ) { fwd[j] = S[i]; j++ } } memcpy(S, … | |
Re: try this: int main() { char* array[4] = { "one", "two", "four", "nine" }; char* test = "four"; check(test, array); getchar(); return 0; } void check(char* test, char* array[]) { int i; for (i = 0; i < 4; i++) { if(strcmp(array[i], test) == 0) { printf("same string: %s\n", array[i]); … | |
Re: The first arg will either be the program name or empty, it's the second arg that will contain "-verbose", so you'll need to check that argc == 2. | |
Re: Just using the first example: y >> 16 & 0xFF0 // y is shifted right by 16 bits, then bitwise and with bitmask 0xFF0 e.g 0xBEEFC000 >> 16 = 0xBEEF 0xBEEF & 0xFF0 = 0xEE0 | |
Re: In your first post, when comparing two char pointers, you'll return the one with the higher memory address. In the second post, you're just comparing the first character of each string, which will return whichever character is alphabetically greater, though it's still not going to perform a string comparison. I … | |
Re: A more compact version of your current code (untested) int histArray[10] = {0}; int minValue; int maxValue; while (terminalArray >= 1 && terminalArray <= 99) { minValue = 1; maxValue = 9; for (int i = 0; i < 10; i++) { if (terminalArray >= minValue && terminalArray <= maxValue) … | |
Re: > You required to write definitions for the given 4 function performing task in the program. Have a go at writing the functions, then post your code and explain what you're having trouble with. **when you post any code, select the code portion and press 'Code' in menu. | |
Re: string nom[100]; int num[100]; int cla[100]; With the method used to specify the arrays, it's impossible to actually delete an entry in the array. It seems from your code that I briefly looked at, you're sorting the arrays, performing a binary search for a particular item and if found you … | |
Re: Check that the return value of the following is a valid pointer : OUTPUT_FILE = fopen(file, "a+"); // what is file? | |
Re: Just specify the precision for your float values as %.2f | |
Re: I haven't tested, but check where I've commented. for (i=0; i<sum; i++) { differenceSquared = pow(userArray[i] - mean, 2); // at this point mean is still 0.0 sumTwo = sumTwo + differenceSquared; } // call function to calculate mean mean = meanStandDev(sum, userArraySize); // mean calculated after it's needed | |
Re: This should work for you. :) [CODE]#include<iostream> using namespace std; class base { public: virtual ~base() { } }; class derived: public base { public: ~derived() { } }; int main() { base *bptr_1 = new derived(); // should check that memory allocation was successful base *bptr_2 = new base(); … |
The End.