nullptr 167 Occasional Poster

Remove the semi colon at the end of line 9, and change the variable type to unsigned int so that you don't get integer overflow.

#include <stdio.h>

int main(void)
{
    unsigned int n, prod, even;
    prod = 1;
    n = 30;

    for (even = 2 ; even <= n; even += 2)
        prod *= even;

    printf("product of all positive even numbers less than or equal to %u is %u\n", n, prod);

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

    return 0;
}
nullptr 167 Occasional Poster

You are incrementing the variable even twice

No, line 10 in the OP's post is not part of the loop, has no bearing on the result and should be omitted.

for(even=2;even<n;even=even+2)
    prod=prod*even; // only this is calculated
nullptr 167 Occasional Poster

find the product of all the positive even numbers less than or equal to 30

You're only calculating the product for positive even numbers less than 30.
So it should be:

prod = 1;
n = 30;

for (even = 2; even <= n; even += 2)
    prod *= even;

printf("Product of all the positive even numbers less than %d is %d\n", n, prod);
nullptr 167 Occasional Poster
#Include<fstream> // should be #include (all lowercase)
#include<>        // what's this meant to be?

You should also check whether your outfile is open.

if (!outfile.is_open() )
{
    // print an error message if you like
    return 1;
}

After writing to outfile, close it: outfile.close();
Instead of writing the entire string character by character you could use:
outfile << str;

Also search these forums for tutorials on code formatting. It's far easier for both you and others to find errors when your code is well formatted.

nullptr 167 Occasional Poster

As tinstaafl indicated, the top of your header file should be:

#ifndef MIXEDEXPRESSION_H // if not defined
#define MIXEDEXPRESSION_H
nullptr 167 Occasional Poster

One possible solution is processing the string in reverse.
So starting from the end of the string, if string element i == c and element i - 1 == c, then erase element i.

std::string squeeze(const std::string& s, char c)
{
    std::string str = s;
    size_t len = str.length();

    // process the string from end to start
    for (size_t i = len - 1; i > 0; --i)
    {
        if (str[i] == c && str[i - 1] == c)
            str.erase(str.begin() + i);
    }

    return str;
}

std::string s1 = "aaaaaahaaaaaaaaaah";
std::string s2 = squeeze(s1, 'a');

output: ahah

nullptr 167 Occasional Poster

The problem lies in:

while(count < len && inputFile >> numsRead[len])
    count++;

You're constantly trying to read to numsRead[8] as len = 8, which is out of bounds for the array.
You need to read to numsRead[count]

You should also check as to whether the file is successfully opened using is_open()

nullptr 167 Occasional Poster

I have to write a fn

Yes you do, so what problem are you having in writing the function?

nullptr 167 Occasional Poster

If nombres.txt is in the same directory as the compiled executable and running under the debugger goes straight to cout<<"algo paso"<<endl - try running the executable outside the debugger.

Some suggestions for your code.
If you put cout << linea << endl at the top of your while loop, you'll notice that you end up with leading whitespace for all but the the first name. So you'll need to trim the whitespace before you do the (nombre == linea) comparison.

while (getline(miArchivo, linea,a ))
{
    cout << linea << endl;
    // Trim leading whitespace
    // Rest of your loop code goes here
}
nullptr 167 Occasional Poster

Could you please post the code you have. The information you've provided so far isn't enough to do anything more than take wild guesses.

nullptr 167 Occasional Poster

You need to process each word (token).

while (inputFile.getline(words, 100))
{
    // Read each word.
    linecount++;
    token = strtok(words, " .\n");

    while(token != NULL)
    {
        // process each token
        longestandshortestWord(token, longestword, shortestword);
        uniquewords(token, uniqueWords, position, uniquewordcounter);
        token = strtok(NULL, " .\n");
        totalnumWords++; // Increment the total number of words in the file.              
    }            
}

Any discrepancies in the results can be overcome by initialising the relevant variables declared at the top of main(...).

If done correctly, your output will be:

Words/Count
------------
the: 5
quick: 2
brown: 2
fox: 2
jumps: 2
over: 2
lazy: 2
dog: 2
now: 1
is: 2
time: 1
for: 2
all: 2
good: 1
men: 1
to: 2
come: 1
aid: 1
of: 1
their: 1
party: 1
i: 1
want: 1
christmas: 1
my: 1
two: 1
front: 1
teeth: 1
a: 1
Total number of lines in file: 4
Total number of unique words in file: 29
Total number of words in file: 44
Longest word: christmas
Shortest word: i
nullptr 167 Occasional Poster

Microsoft Network Monitor will allow you to track internet activity by process name and PID.
http://www.microsoft.com/en-au/download/details.aspx?id=4865

nullptr 167 Occasional Poster

Write a C++ program that reads lines of text from a file using the ifstream getline() method

The ifstream getline() method, is different to the std::getline method in that it uses a char* - a pointer to an array of characters to hold the data, not a std::string object.
Refer to http://www.cplusplus.com/reference/istream/istream/getline/
So re-read the brief that you are given and use the methods specified.

nullptr 167 Occasional Poster

You just need to cast sum as type float.

float average (int sum, int size)
{
    return static_cast<float>(sum) / size;
}
nullptr 167 Occasional Poster
int Clip(int Val)
{
    return (Val < 0 ? 0 : (Val > 0xFF ? 0xFF : Val & 0xFF));
}

My simple contribution.

rubberman commented: Just what I was going to post! :-) +12
nullptr 167 Occasional Poster

Seeing as start and last are both int, you just need to cast &a[1].num1 and &a[0].num1 as type int.
start = (int) &a[1].num1;
Or quite simply you could use:
printf("\nsize of structure :%d bytes", sizeof(a[0]) );

nullptr 167 Occasional Poster

Seeing as you're wanting to close the window, the main problem you're going to have is that with protected mode/IE7+ the first process created is a broker process that then then launches a low integrity process. This second process is the one you see, but the handle returned from ShellExecuteEx or CreateProcess is the handle to the broker process, which isn't of much use to you.

Using the com interface IWebBrowser2 would allow you to close the window:

#include <ExDisp.h>
#include <comutil.h>

#pragma comment (lib, "comsupp")

int wmain()
{
    if (SUCCEEDED(OleInitialize(nullptr)))
    {
        IWebBrowser2 *pBrowser = nullptr;

        CoCreateInstance(
            CLSID_InternetExplorer, 
            nullptr, 
            CLSCTX_LOCAL_SERVER, 
            IID_IWebBrowser2, 
            reinterpret_cast<void**>(&pBrowser)
            );

        if (pBrowser)
        {
            VARIANT vEmpty;
            VariantInit(&vEmpty);

            _bstr_t strURL = L"http://www.google.co.uk";

            HRESULT hr = pBrowser->Navigate(strURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
            if (SUCCEEDED(hr))
            {
                pBrowser->put_Visible(VARIANT_TRUE);
                // wait 5 seconds
                Sleep(5000);               
            }

            // close window and clean up
            pBrowser->Quit();
            pBrowser->Release();
        }

        OleUninitialize();
    }

    return 0;
}
nullptr 167 Occasional Poster

Read the documentation on the SHELLEXECUTEINFO structure at http://msdn.microsoft.com/en-us/library/windows/desktop/bb759784(v=vs.85).aspx
In particular regarding the hProcess member.

nullptr 167 Occasional Poster

Something like:

Qstring str = textEdit->toPlainText();
// TODO convert str to uppercase
textEdit->setPlainText(str);

ref: http://harmattan-dev.nokia.com/docs/library/html/qt4/qtextedit.html

nullptr 167 Occasional Poster
x=1;  
y=1;

if ( n > 0)
    x = x + 1; // this line will only be evaluated if (n > 0)

y = y - 1;    // this line will always be evaluated regardless of the value of n

Hopefully the comments I've included above will clarify things.

nullptr 167 Occasional Poster

The way the code is currently written, only the first expression after if (n > 0) will be evaluated, provided that n is indeed greater than zero.
Rewriting the code using braces it would be equivalent to:

x=1;  
y=1;

if (n > 0)
{
    x = x + 1; // only this can possibly be evaluated
}

y = y - 1;

printf("%d %d", x, y);

If you want both expressions x = x + 1 and y = y - 1 to be evaluated, then they both need to be enclosed between braces:

if (n > 0)
{
    x = x + 1;
    y = y - 1;
}
nullptr 167 Occasional Poster

i want to knw how 14.375 float is same as 14.375 double in memory but no so for 14.385.

Likely because 14.375 is exactly 14 3/8 which would fit the floating point model used.

nullptr 167 Occasional Poster
class A
{
    int a[]; // zero sized array
};

You should receive a warning when compiling this due to int a[] being a zero sized array.

nullptr 167 Occasional Poster

line 44 should be int main() and obviously return an int value.

line 42 int total_scores(const int [][Cols], int)
line 58 int total_socres(const int array[][Cols], int Rows) notice the spelling mistake?

line 65 total = total + array [Rows][Cols]; - so for each iteration you are adding array[3][3] which is out of bounds for the array and would just contain memory junk.

It should be total = total + array[i][j]; which is equivalent to total += array[i][j];

As for getch(), using cin.get() would be preferable.
Better code formatting would be helpful both for you and others reading your code.

nullptr 167 Occasional Poster

What are you trying to achieve in line 9 with count 1

For a default constructor that initializes count to zero:

class counter {
    int count;
public:
    counter() : count(0){ }
};
nullptr 167 Occasional Poster

What compiler are you using?
The output I get from VS 2012 is: 0 3 8 15 24

nullptr 167 Occasional Poster

In your original code you have: for (i = 0; i < n; i++) which increments i by 1 for each iteration.
The solution is to increment i by 2 for each iteration.
i += 2 // equivalent to i = i + 2

nullptr 167 Occasional Poster

try this:-

> 1.ch=getch();
> 2.if(ch=='y')
> 3.main();

Please do not do this. Follow Moschops link on loops.
getch() is not standard and so shouldn't be used.
Recursive calls to main() are simply a terrible practice and should never be done.

nullptr 167 Occasional Poster

Just specify a file size equal to (size of file you're mapping + size of extra data) when you call CreateFileMapping.
Read http://msdn.microsoft.com/en-au/library/windows/desktop/aa366542(v=vs.85).aspx - specifically the part about File Mapping Size.

nullptr 167 Occasional Poster
nullptr 167 Occasional Poster

You need to put begin and end in your while loop.

While num <> 999 do
begin
  // code for the loop goes here
  //
end;

Also line 3 isn't needed.
I'll leave you to work out the rest.

nullptr 167 Occasional Poster
nullptr 167 Occasional Poster

Yes that's fine, though you could avoid the use of a global variable by declaring static test t; inside main and the passing the variable instance to your display function.

void display(const test &t)
{
    // rest of code
}

and call it with display(t);

nullptr 167 Occasional Poster

By using the key word typedef, you are just defining the struct and no memory is being allocated for it. Hence, static test *p; is not pointing to any valid memory location.

If using a typedef for your struct use something like:

typedef struct _test {
    int array[10];
} test, *ptest; 

Where test and ptest are the types used by your variables.
e.g test t = {0}; for static allocation, ptest p = new test; for dynamic allocation.

So to dynamically use the struct you'd have:

int main(int argc, char* argv[])
{
    ptest p = new test; // allocate memory
    if (nullptr == p)   // check whether memory was allocated
        return 1;

    p->array[0] = 10;
    std::cout << p->array[0] << std::endl;

    delete p; // free the memory

    std::cin.get();

    return 0;
}
nullptr 167 Occasional Poster

You need to flush the input stream after line 22. Refer to this article for the why and how - http://www.daniweb.com/software-development/cpp/threads/90228/flushing-the-input-stream

nullptr 167 Occasional Poster

duplicate - ignore

nullptr 167 Occasional Poster

This appears to work fine.

SetForegroundWindow(hWnd);
if (!IsWindowVisible(hWnd) || IsIconic(hWnd))
{     
    ShowWindow(hWnd, SW_MINIMIZE);
    ShowWindow(hWnd, SW_RESTORE);
}
nullptr 167 Occasional Poster

Untested, but this should work provided you're running in the same session as the target process.

if (!IsWindowVisible(hWnd))
{
    ShowWindow(hWnd, SW_MINIMIZE);
    ShowWindow(hWnd, SW_RESTORE);
}

SetForegroundWindow(hWnd);
nullptr 167 Occasional Poster

Use ChangeServiceConfig2 with dwInfoLevel of SERVICE_CONFIG_DESCRIPTION.

nullptr 167 Occasional Poster

Could you post your code for opening and reading the files? What specific problems are you having?

nullptr 167 Occasional Poster

line 9: You're trying to read everything into the same address space - &image_read[50][100]
Try changing it to - fscanf(myFile,"%d", &image_read[i][j]);

Ancient Dragon commented: Good Catch :P) +14
nullptr 167 Occasional Poster

You're conversion from Fahrenheit to Celsius isn't correct. Try:

double celsius(double F)
{
    return F*9.0/5.0 + 32;
}
nullptr 167 Occasional Poster

You've got if (isalnum(word[i])), which basically means if word[i] is either a letter of the alphabet or numeric, you're failing it.
What you want to do is contained in Moschops reply. Check whether isalpha(word[i]) is false.
Also, when you get the new word on failure, you're not resetting i and you'd also want to use continue; after that so that you skip the i++ at line 12.

nullptr 167 Occasional Poster

But now how to do it with left shift command instead of multiplication?

Ask yourself the following: what is the result of 1 << 0, 1 << 1, 1 << 2, 1 << 3 etc
Do you notice the pattern?

nullptr 167 Occasional Poster

Here's you're example with some padding to show what happens when b and c are interchanged.

struct aa {
    char a:3;      // bits 0..2 of char
    char c:2;      // bits 3..4 of same char
    char unused:3  // most significant 3 bits of the same char
    char pad[3];   // pad to 4 byte boundary
    int b:30;      // bits 0..29 of int
};

This would give a size of 8 bytes.
Unfortunately, I don't have a gcc compiler with me at the moment to explain why the following would also produce a size of 8.

struct aa {
    char a:3;
    int b:30;
    char c:2;
};
nullptr 167 Occasional Poster
struct aa {
    char a:3;  // the least significant 3 bits of the char
    int b:30;  // bits 0 to 29 of the integer
    char c:3;
};

With regular 4 byte alignment, you'll have a, b and c each using 4 bytes = 12 bytes.

but when i replace size of c to 2 then it gives 8 why is that so?

I'm unable to reproduce this, with char c:2 the same alignment applies and should produce a size of 12 bytes.

nullptr 167 Occasional Poster

Seeing as you're taking user input for the day, what constitutes a valid day? If I enter 3 for each day, what happens to every other entry in the array? What happens if I enter day values far beyond the bounds of the array? How about non numeric input?

If you're taking user input, you must validate the input and handle erroneous input.

nullptr 167 Occasional Poster

I gather your using TCHARs and most likely compiling as _UNICODE, so try:

HRSRC hRes = FindResource (NULL, TEXT("ID_LIBMYSQL"), TEXT("RT_RCDATA") );
nullptr 167 Occasional Poster

Yes, I could indeed do that. Could you perhaps be a little more specific as to what a tough program is?

nullptr 167 Occasional Poster

re: firstPerson's code

int lastLargestIndex(int arr[], int size)

{
    int lastLargestIndex = 0;
    int tem = arr[0];
    int i;
    for(i = 0; i < size; i++)
    {
        if (arr[i] > tem)
        {
            lastLargestIndex = i;
            tem = arr[i];
        }
    }
    return lastLargestIndex;
}

Consider if the array has duplicate entries.

int arr[15] = {5,11111,76,9,4,2,15,8,21,34,99,3,6,13,11111};

Using (arr[i] > tem) will return the last highest index being index 1, because the value of arr[14] is not greater than the value of arr[1].

That's why you need if (arr[i] >= tem)