nullptr 167 Occasional Poster

Just install the 2012 VC++ Redistributable - http://www.microsoft.com/en-us/download/details.aspx?id=30679

nullptr 167 Occasional Poster

I just threw this together for testing purposes:

using namespace std;

void ReadtheFile();

string getcmd;
ifstream FileName;
char InBuffer[64];

int _tmain(int argc, _TCHAR* argv[])
{
    ReadtheFile();
    getchar();

    return 0;
}

void ReadtheFile()
{   
    size_t Data_Length;
    FileName.open("Credit.txt");
    if (FileName.fail() )
    {
        cout << "error opening file" << endl;
        return;
    }

    while (getline(FileName, getcmd) )
    {
        if (getcmd.empty() )
        {
            continue;
        }

        memset(InBuffer, 0, 64); 
        string subString_is = getcmd.substr(0, 4); // read length 4
        memcpy(InBuffer, subString_is.c_str(), subString_is.size() );

        switch (InBuffer[0]) 
        {
        case 'K': 
            if (InBuffer[1] == 'L')
            {
                memcpy(&InBuffer[4], "123456", 6);            
                memcpy(&InBuffer[10], "0987", 4);                         
            }
            break;

        default:
            break;
        }

        Data_Length = strlen(InBuffer);    
        cout << string(InBuffer) << " length: " << Data_Length << endl;             
    }
    FileName.close();
}


Credit.txt
-------------------------
KL10
PM00  

KL10
CRAP

-------------------------

Output:

KL101234560987 length: 14
PM00 length: 4
KL101234560987 length: 14
CRAP length: 4
anukavi commented: Hi, will change my code as per ur design and will get back to u. +0
nullptr 167 Occasional Poster

It would likely be worth posting more of your code rather than just the snippets we see. Otherwise all I can do is guess that it's probably a scope problem with where the variables are declared.

anukavi commented: Thanks..ok give me some time, will post it +0
nullptr 167 Occasional Poster

What compiler are you using?

char InBuffer[64];  // char InBuffer[64] = {0};
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);
memcpy(&InBuffer[4],"123456",6);
memcpy(&InBuffer[10],"0987",4);

unsigned __int32 len = strlen(InBuffer); // I get len = 14

Edit, I just noticed you have:

case 1:
char InBuffer[64];
BOOL flag=0;
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);

case 2:
char InBuffer[64];
BOOL flag=1;
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);
memcpy(&InBuffer[4],"123456",6);
memcpy(&InBuffer[10],"0987",4);

When declaring variables in a switch you need to use braces:

case 1:
{
    char InBuffer[64];
    BOOL flag=0;
    memset(InBuffer,0,64);
    memcpy(InBuffer,"KL10",4);
    break;   // so it doesn't keep dropping through all the cases
}
nullptr 167 Occasional Poster

You've got:

    memcpy(InBuffer,"KL10",4);
    memcpy(&InBuffer[4],"123456",6);
    memcpy(InBuffer[10],"0987",4);

Do you see the error in line 3?

nullptr 167 Occasional Poster
    void getTopTwoScores(double scores[], int numScores, double& highest, double& secondHighest)
    {
        if (numScores == 1)
        {
            highest = secondHighest = scores[0];
            // nothing else to do
            return;
        }

        // initialize highest and secondHighest
        // assume highest is scores[0]
        // secondHighest we'll set to negative maximum double value
        highest = scores[0];
        secondHighest = - std::numeric_limits<double>::max();

        for(int i = 1; i < numScores; i++)
        {
            if(scores[i] > highest || scores[i] > secondHighest)
            {
                if (scores[i] > highest)
                {
                    secondHighest = highest;
                    highest = scores[i];
                }
                else
                {
                    secondHighest = scores[i];
                }
            }
        }
    }

Also in your main(), verify that scoreCount > 0 and you'll also need to flush the input stream to get rid of any new line chars.

nullptr 167 Occasional Poster

I have got an integer as 0010000001

Is 0010000001 binary? If it is, just shift right the number of digits to remove.

If it's just a decimal integer then num/10000 seems logical.

anukavi commented: its not binary,, its exactly 10 digit number ,so as of now foll.this logic.Thanks +0
nullptr 167 Occasional Poster

find 2 ^ k
Seeing as you can't use the pow(...) function, you could just use bit shifts.

2 << (k - 1)

2 shift left (k -1 ) will give you 2 to the power of k, where k is an unsigned whole number.

nullptr 167 Occasional Poster

I really don't have the time at present to go through all your code.
One thing that immediately stands out is:

private:
    Node *attachedNodes[4];

Your code is using attachedNodes[0] .. attachedNodes[4] inclusive, which equals 5 Nodes not 4.

nullptr 167 Occasional Poster

Here's some code for your 3rd function.

void aretheysame(int x, int y, int z)
{
    if (x == y && y == z)
    {
        cout << "All numbers equal" << endl << endl;
        return;
    }

    if (x != y && y != z && x != z)
    {
        cout << "All numbers different" << endl << endl;
        return;
    }

    if (x == y && x > z || x == z && x > y || y == z && y > x)
    {
        cout << "Two numbers are equal, the other is lower" << endl << endl;
    }
    else
    {
        cout << "Two numbers are equal, the other is higher" << endl << endl;
    }

    return;
}
nullptr 167 Occasional Poster

That's because you haven't changed the function and are still returning a char. return serviceCode;
Just change it to return;

void getServiceCode (char &serviceCode)
{
    cout << "Please enter your service code: ";
    cin >> serviceCode;
    return;  // this line can be omitted, though I prefer to include it.
}
nullptr 167 Occasional Poster

You have a function declaration of char getServiceCode (char serviceCode); that you try to pass your char serviceCode variable to.

You need to either pass the variable instance or a pointer to the variable, otherwise nothing will be assigned from the function to the serviceCode address space.

Just change your function to: void getServiceCode(char &serviceCode)
That way you'll be working directly with the instance of variable serviceCode, hence no reason to return a char.

The same also applies to your getAcctNumber function.

nullptr 167 Occasional Poster

Childish rubbish that's not worth discussing.
Read the forum rules http://www.daniweb.com/community/rules

nullptr 167 Occasional Poster

It all looks fine to me too, just a few things to clean up:
*Close the file when you're finished with it - in.close();
*Pause execution to read the string ( cin.get() or similar) and then return 0;

nullptr 167 Occasional Poster

Try changing the following -

line 3:   int again='y';
line 14:  again = getch();
kidpro commented: Thx dear +0
nullptr 167 Occasional Poster

What type of variable is input? Where are you getting the data from that you need to count spaces in?

if input is of type char, then you'd have:

if (input == ' ') // not ''
        space++;

if it's a std::string then:

    if (input == " ")
nullptr 167 Occasional Poster

see below

nullptr 167 Occasional Poster

Using modular arithmetic as already suggested by ken, work out what expressions need to be evaluated in order to produce an output of
arr[0][0] arr[0][2] arr[1][1] arr[2][0] arr[2][2]

nullptr 167 Occasional Poster

what I should write beside return ?

Use cout to inform you what max is.
Pause execution before return 0; so that you can see the result.

After that, look at ways to optimize your maxValue function.

nullptr 167 Occasional Poster

Perhaps CreateTimerQueue, CreateTimerQueueTimer, DeleteTimerQueueTimer would do what you want. Plus it's easy to wrap them into a class.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682483%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687003%28v=vs.85%29.aspx

nullptr 167 Occasional Poster

Seeing as my previous post didn't help, could you please clarify exactly what you're wanting to do?

nullptr 167 Occasional Poster

Initialize WNDCLASS as already suggested and after your call to ShowWindow(...), call

UpdateWindow(hWnd);
nullptr 167 Occasional Poster

I'm not sure whether this is what you're after:

#include<iostream>
#include <iomanip>
//#include<fstream>

using namespace std;


int main()
{
    int input = 1;
    int board[3][4];

    for(int i=0; i<3; i++)    //This loops on the rows.
    {
        for(int j=0; j<4; j++) //This loops on the columns
        {
            board[i][j] = input; 
            input++;
        }
    }

    for(int i=0; i<3; i++)    //This loops on the rows.
    {
        for(int j=0; j<4; j++) //This loops on the columns
        {
            cout << setw(2) << board[i][j]  << "  "; // setw(2) for alignment
        }
        cout << endl;
    }

    cin.get();

    return 0;
}
nullptr 167 Occasional Poster

Can I get the question's solution?

No, you won't receive any help until such time as you present code that demonstrates that you've made a genuine attempt to solve the problem.

nullptr 167 Occasional Poster

Fix:
line 19, flase should be false
line 32, should be lo = mid;
line 49, should be }while(toupper(reply) == 'Y');

nullptr 167 Occasional Poster

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 ptr        
    }


}
nullptr 167 Occasional Poster
  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.
nullptr 167 Occasional Poster

Have a look from lines 13 to 16, you're writing beyond the bounds of the allocated array.

nullptr 167 Occasional Poster

You can also replace the strcpy_s(...) with the string copy member function.

    char destPath[MAX_PATH] = {0};
    char sourcePath[MAX_PATH] = {0};

    dest.copy(destPath, dest.length(), 0);
    source.copy(sourcePath, source.length(), 0);
nullptr 167 Occasional Poster

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() );
    if (0 != error)
    {
        // handle error
        return FALSE;
    }

    //SHFile Struct
    SHFILEOPSTRUCTA fileStruct = { 0 }; 
    fileStruct.wFunc = FO_COPY;
    fileStruct.pTo = destPath;
    fileStruct.pFrom = sourcePath; 
    fileStruct.fFlags = FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;
    //...
    int iret = SHFileOperationA(&fileStruct);

    return (iret == 0 && fileStruct.fAnyOperationsAborted == FALSE);
}
nullptr 167 Occasional Poster

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?
}
nullptr 167 Occasional Poster

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, halfnum, count, index;

    for (num = 4; num <= 100; num++)
    {
        halfnum = num/2;
        count = 0;                      
        for (i = 2; i <= halfnum; i++)
        {
            if(num % i == 0)
            {
                count += 1;
            }
        }
        // store
        countstore[num] = count;                
    }

    //result stores the number of distinct divisors, index stores the number for which the greatest distinct divisors have been found

    result = 0;
    //note: this does not contain all possible results as numbers with equal greatest amount of divisors
    //      will not be included.

    for (i = 4; i <= 100; i++)
    {
        if (result < countstore[i])
        {
            result = countstore[i];
            index = i;
        }
    }

    printf("the integer between 0 and 100 with %d number of distinct divisors is %d\n\n", result, index);

    system("pause");

    return 0;
}
nullptr 167 Occasional Poster

In line 18 you haven't defined the operator. Try

friend ostream &operator<<(ostream &mystream, Circle &c);
nullptr 167 Occasional Poster

Post your code, my crystal ball is away being polished.

nullptr 167 Occasional Poster
nullptr 167 Occasional Poster

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 the number in the array until you reach array[N - 1]
You would also want to validate that the number N entered is not more than the number of integers between 10 and 40 inclusive.

TrustyTony commented: Good thinking of mathematical consequences of uniqueness: ' not more than the number of integers between 10 and 40 inclusive' +12
nullptr 167 Occasional Poster

How can I eliminate the "high, reserved byte" or ensure it is set to 0?

color = GetPixel(hdc_, 10, 10) & 0xFFFFFF;
nullptr 167 Occasional Poster

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;
}
nullptr 167 Occasional Poster

As well as pyTony's suggestion, in lines 12 and 13 you are trying to open the same file twice.

nullptr 167 Occasional Poster

Simpler solution is to replace lines 10 to 15 with

while (iarr[++j] == 0 && j < len - 1) ;
nullptr 167 Occasional Poster

Then don't show them.

for (i = 0; i < len; ++i)
{
    if (! iarr[i])
        break;

    printf("%d ", iarr[i]); // 1 3 5 7 9 9 6
}

Also in my previous post, lines 10 to 15 can be replaced with:

while (iarr[++j] == 0 && j < len) ;
nullptr 167 Occasional Poster

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 < len; ++idx)
    {
        if (iarr[idx] == 0)
        {
            j = idx;
            ++j;

            while (iarr[j] == 0 && j < len)
            {
                ++j;
            }

            iarr[idx] = iarr[j];
            // set substituted value to zero
            iarr[j] = 0;
        }
    }

    for (i = 0; i < len; ++i)
    {
        printf("%d ", iarr[i]); // 1, 3, 5 ,7, 9, 9, 6, 0, 0, etc
    }
nullptr 167 Occasional Poster

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 have at line 10:

if ((in = fopen("input.txt", "r")) == NULL) // Opens the text file containing values
{
    printf("The file cannot be opened\n"); // Displays message if text file cannot be opened
    return 0;                              // ** add this otherwise you'll needlessly proceed to the next part of the code.
}
nullptr 167 Occasional Poster

If this is an assignment task of some sort, then consider the following.

  1. int x = 123456;
  2. In each while loop you have x /= 10;
  3. What is the value of x after the first loop?
  4. How many times do you need to loop until while (x > 0) is false?
  5. If you've followed that, then you'll see the correlation between the number of digits in x and the number of loops needed.
nullptr 167 Occasional Poster

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++ > 0 ) 
    {
        y *= 10;
        y += x % 10;
        x /= 10;

        if  (x <= 0)
        {
            break;
        }
    }
nullptr 167 Occasional Poster
  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);

nullptr 167 Occasional Poster
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 (i = _fact ; i >= 1; i--)
        {
            result *= i;
        }
        printf("factorial of (%d) = %d\n", _fact, result);
    }

    printf("\npress Enter to exit\n");
    getchar();

    return (EXIT_SUCCESS);
}
nullptr 167 Occasional Poster

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.

nullptr 167 Occasional Poster
#include <iostream>
#include <fstream>

using namespace std;

//  code
nullptr 167 Occasional Poster

Check out IsZoomed function.