WolfPack 491 Posting Virtuoso Team Colleague

Well I ran a piece of code under a debugger. The value I entered was 0.0000124568 but the value stored by the program which I saw using the debugger was 1.2456800000000001e-005. You can see an unnecessary '1' marked in red. Since this is a problem due to the representation of floating point decimal numbers in binary, the only way I see to get around it is to enter the double value as a char array and search for the decimal point in the array. But even then you will have to know the maximum length of a value that can be entered.

WolfPack 491 Posting Virtuoso Team Colleague

This part returns NULL.

hWnd = CreateWindowEx(	(DWORD)		dwExStyle,
								(LPCTSTR)	lpClassName,
								(LPCTSTR)	lpWindowName,
								(DWORD)		dwStyle,
								(int)		x,
								(int)		y,
								(int)		nWidth,
								(int)		nHeight,
								(HWND)		hWndParent,
								(HMENU)		hMenu,
								(HINSTANCE)	hProgInst,
    							(LPVOID)	lpParam);
		if ( hWnd == NULL )
		{
			MessageBox(NULL, "CreateWindow Returned NULL", "Error", MB_OK );
			return;
		}
WolfPack 491 Posting Virtuoso Team Colleague

I'm probably missing some math aspect here, but couldn't you convert 4.33 to a string, find out what position the . is and have your answer?

I also think that this is the simplest and ,the most accurate, answer. Great solution. :idea:

WolfPack 491 Posting Virtuoso Team Colleague

I dont know what you are trying to do. But try replacing your main file with the one I have attached. It is a skeleton window procedure. It worked for me.No problems with menus or whatever.

WolfPack 491 Posting Virtuoso Team Colleague

There was nothing wrong with your rc file. I am using the Visual Studio IDE, and here is what I did to make the project compile.

1. Rename .rc to main.rc 2. Create a new file resource.h 3. Put the

#include <windows.h>

#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
#define ID_STUFF_ABOUT 9003
#define IDD_TOOLBAR 9004
#define IDC_PRESS 9005
#define IDC_OTHER 9006
#define ID_DIALOG_SHOW 9007
#define ID_DIALOG_HIDE 9008
#define ID_HELP_ABOUT 9009
#define IDD_ABOUT 9010

of your main.cpp file to the resource.h file.
4. Added

#include "resource.h"

to your main.cpp file and main.rc file.
5. Added the above 3 files to a Visual Studio Solution and built it..

After that the program ran okay. I dont know the procedure for dev-Cpp. But I think you will have to do the above 4 steps for any compiler. Try it and tell the result. Only the way you compile; step 5, will change for Dev-Cpp. Here are the modified files.

WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

Try putting all the definitions,

#include <windows.h>

#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
#define ID_STUFF_ABOUT 9003
#define IDD_TOOLBAR 9004
#define IDC_PRESS 9005
#define IDC_OTHER 9006
#define ID_DIALOG_SHOW 9007
#define ID_DIALOG_HIDE 9008
#define ID_HELP_ABOUT 9009
#define IDD_ABOUT 9010

to a resource.h file and including the resource.h file to both your .rc file and main.cpp file. I dont know if the compiler allows the present rc file name. It hasn't got a file name. Only an extention. Correct that also.

What is the compiler you are using. Is it a IDE or command line compiler?

WolfPack 491 Posting Virtuoso Team Colleague
#include <iostream>
int main()
{
	char* test = "testing is a'test string";
	char* ch = test;
	int count = 0;
	while( (ch = strstr( ch, "test")) != 0)
	{
		if ( ch != test )// Check if you are at the beginning of the string
		{
			ch--;
			if( ch[ 0 ] == ' ' || ch[ 0 ] == '\'')
			{
				count++;
				ch ++;
				// Output the result
				std::cout << count << std::endl;
				std::cout << ch << std::endl;
				ch ++;
			}
		}
		else
		{
			count++;
			std::cout << count << std::endl;
			std::cout << ch << std::endl;
			ch++;
		}
	}
	return 0;
}

Modify for your requirements.

WolfPack 491 Posting Virtuoso Team Colleague
char ch = temp[ i - 1]; // i is the current position ; i must be greater than 0
if( ch == ' ' || ch == '\'')

or

// i is the current position ; i must be greater than 0
if( temp[ i - 1]== ' ' || temp[ i - 1]== '\'')
WolfPack 491 Posting Virtuoso Team Colleague

Nothing. I said that because I didnt know your requirements. If it meets your requirements then it is correct.

WolfPack 491 Posting Virtuoso Team Colleague

Use this.

while( ( (ch = strstr( ch, "jo ") ) != 0) ||( (ch = strstr( ch, ",jo ")) != 0 ))

Note:
I am not sure about the logic, that is your responsibility. But the syntax is okay.

WolfPack 491 Posting Virtuoso Team Colleague

$(TargetDir)$(TargetName).pdb

Okay that is what is expected. Try Dragon's suggestion.

WolfPack 491 Posting Virtuoso Team Colleague

Another thing, can you tell me what is in the field "Generate Program Database File" that is located right below the "Generate Debug Info" field?

WolfPack 491 Posting Virtuoso Team Colleague

Although setting the breakpoint at the current position looks okay, for now set the breakpoint at

maxlen = max(maxlen, record.name.size());

and see if the program stops at that point. If you already didnt know you have to press F10 to execute the code line by line. If it doesnt stop even then, there is someother problem, but I cant seem to get the cause.

WolfPack 491 Posting Virtuoso Team Colleague

Maybe the line where you set the breakpoint is not executed. Could you give us the part of the program where you set the breakpoint? The line where the breakpoint is set and 2 or 3 lines above and below it will do.

WolfPack 491 Posting Virtuoso Team Colleague

Right Click your project from the project explorer.
Go to Configuration Properties->Linker->Debugging
Most probably the Value in the "Generate Debug Info" should be "No".
Set it to "Yes (/Debug)" and try debugging again.

WolfPack 491 Posting Virtuoso Team Colleague

Put a brace here.

if (y <= x)
{
z = x - y;
cout << "There is enough room at the meeting for " << z << " more people too attend.\n" << endl;
}
else
{
cout << "In order to have the meeting " << y - x << " people need to leave the room.\n" << endl;
}

It is good programming practice if you use braces for all the if else statements. Even if they have only one statement after the condition.

WolfPack 491 Posting Virtuoso Team Colleague

I thought that I wouldnt have to close the handle to the file if hFile = INVALID_HANDLE_VALUE

Actually you dont have to close it if

hFile == INVALID_HANDLE_VALUE

. But in this case the condition is

if ( hFile != INVALID_HANDLE_VALUE )
{ 
...

. So you have to close it before trying to open it again.

WolfPack 491 Posting Virtuoso Team Colleague

you use

samp obj[SOME_CONSTANT]

for static memory allocation. The storage area is assigned at compile time.
The keywork new in C++ is like malloc in C. You use it to create a memory storage area at runtime. This memory is created in the free store. So you have to call delete for each new statement you use. Since you want x numbers of Samp at runtime and not compile time, you cant use the static array. You must use the dynamic allocation in the form of

Samp* obj = new Samp[ x ]; // Allocate Memory

....
delete [] obj;// Deallocate Memory
WolfPack 491 Posting Virtuoso Team Colleague

Sorry my mistake.
It should be this.

Samp* obj = new Samp[ x ];

sorry again.

WolfPack 491 Posting Virtuoso Team Colleague

Guess it is because of this part.

int x;
cin>>x;
samp obj[x];

either define an array of samp like samp obj[ 10 ] or use the new operator like this. samp* obj = new samp(x);

WolfPack 491 Posting Virtuoso Team Colleague

status

WolfPack 491 Posting Virtuoso Team Colleague

Okay. Got it. You are trying to open the same file twice.
Here are the culprits.

case CM_FILE_SAVE:
{
	//...
	HANDLE hFile;
	hFile = CreateFile( WindowText, GENERIC_READ, FILE_SHARE_READ, NULL,
				OPEN_EXISTING, 0, NULL );
	// This function is successfull only when there is a file of name WindowText.
	if ( hFile != INVALID_HANDLE_VALUE )
	{
		// YOu are here because hFile is valid. i.e the File is open.
		// Now you are calling save File. Go to the SaveFile now.
		if ( !SaveFile( hwnd, GetDlgItem( hwnd, IDC_CHILD_EDIT ), WindowText )) 
		{
			MessageBox( hwnd, "Could not save file", 0, MB_ICONERROR );
		}
	}
	else
	{
	//...
	}
}
BOOL SaveFile( HWND owner, HWND hEdit, LPCTSTR pszFileName )
{
	HANDLE hFile;

	// We are here because hFile was valid. ie a File of pszFileName is open already. But you call CreateFile again.

	// Try to create a file of name pszFileName...
	hFile = CreateFile( pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
				FILE_ATTRIBUTE_NORMAL, NULL );

	// But we had opened it before calling this function remember?
	// Therefore this hFile should be Invalid with Access Error.

	if ( hFile != INVALID_HANDLE_VALUE )
	{
		// Will not go here if the file exists...
	}
	else
	{
	}
	return bSuccess;
}

Did you get where you are going wrong? You can fix it with a crude fix like this.

case CM_FILE_SAVE:
{
	//...
	HANDLE hFile;
	hFile = CreateFile( WindowText, GENERIC_READ, FILE_SHARE_READ, NULL,
				OPEN_EXISTING, 0, NULL );
	// This function is successfull only when there is …
WolfPack 491 Posting Virtuoso Team Colleague

The functions in time.h are only accurate to 1 second -- so no matter how you divide it you still have only 1 second accuracy. You need to use other functions, such as clock(), or win32 api function GetTickCount(), or GetSystemTime() that provide more accuracy.

Do you know the resolution of those functions. As I said earlier I remember that Clock() had only a resolution of 1ms.

WolfPack 491 Posting Virtuoso Team Colleague

I maybe wrong, but I remember reading in a Visual Studio 6.0 book that the best resolution possible in it is 1 millisecond. So if that is the case you wont be able to measure 0.00045 seconds. It will come as 0.

PS.
Isn't the greeting "Respected Sir/madam" a bit out of date? It drives me nuts.

WolfPack 491 Posting Virtuoso Team Colleague

Modify your RegisterInput function as follows.

VOID RegisterInput(HWND hWnd;)
{
	Rid.usUsagePage = 0x01; 
	Rid.usUsage		= 0x06; 
	Rid.dwFlags		= RIDEV_INPUTSINK;
        Rid.hwndTarget = hWnd; // The Window Handle of your window
	if (RegisterRawInputDevices(&Rid, 1, sizeof(Rid)) == FALSE) ErrorTest("Error registering input");
}
WolfPack 491 Posting Virtuoso Team Colleague

You should create a single structure with the required arguments as members and pass it to the _beginthread function.

WolfPack 491 Posting Virtuoso Team Colleague

Iam running out of options here. I also think that the SaveFile function is okay. If the filename is correctly returned from GetSaveFileName, the SaveFile function should behave identically in both cases. This is a long shot but try,

char szFile[MAX_PATH] = "";
 ofn.lpstrFile = szFile; 
//....Initialise rest of structure...
 //Pass the structure into GetSaveFileName

If that does not work, I advice you to post the full code of the SaveFile and SaveFileAs functions.

WolfPack 491 Posting Virtuoso Team Colleague

It is difficult to point out the cause from here. It will be better if you set a breakpoint just after the call for the GetSaveFileName function and see if all the fields, especially the file name of the OPENFILENAME structure, are filled properly. You better use the ofn.Flags = OFN_OVERWRITEPROMPT; Statement before the GetSaveFileName call if you are not doing so already.

WolfPack 491 Posting Virtuoso Team Colleague

shares

WolfPack 491 Posting Virtuoso Team Colleague

Some other things that I saw later..
listen and bind and maybe the other functions also, return 0 on correct operation. So the code

if ( bind( parameters...) )
{
      //COrrect op
}
else
{
        // wrong
}

is wrong.
It should be

if ( bind( parameters ) == 0 )
{
       //Correct Operation
}
else
{
       //Error
}

Refer the Specifications of the bind, listen, connect, etc. functions and correct the code accordingly.

WolfPack 491 Posting Virtuoso Team Colleague

Use this before using the Winsock Functions

WSADATA wsaData;
	int Ret;
    if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)
   {
      printf("WSAStartup failed with error %d\n", Ret);
      return;
   }
WolfPack 491 Posting Virtuoso Team Colleague
#include <iostream>
#include <ctime>

int main()
{
	time_t time_now;
	time(&time_now);
	struct tm *tm_now = localtime(&time_now);
	std::cout << tm_now->tm_hour << " " 
		<< tm_now->tm_isdst << " " 
		<< tm_now->tm_mday << " " 
		<< tm_now->tm_min << " " 
		<< tm_now->tm_mon << " " 
		<<tm_now->tm_sec << " " 
		<< tm_now->tm_wday << " " 
		<< tm_now->tm_yday << " "
		<< tm_now->tm_year + 1900 
		<< std::endl;
	return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

Just as I thought...Most probably you have opened it using another application. Since it is a Rich-Edit Control, my best guess is that you have opened it using MS-Word and trying to overwrite it while it is open..

WolfPack 491 Posting Virtuoso Team Colleague

Why dont you use the GetLastError Function to get the detailed error number? Then you will be able to find why it is failing.

WolfPack 491 Posting Virtuoso Team Colleague

How can I give these arguments in project settings?

If you are using Visual Studio 6.0 You can
-Project--->Settings--->Debug Tab---->Project Arguments

If you are using Visual Studio .NET
-Project-->Properties--->Configuration Properties--->Command Arguments

How can I run these project from command prompt?

OPen a Command Prompt
Go to the Dubug or Release Folder of your Project.
Type the name of the Executable and the desired Command line Arguments.

WolfPack 491 Posting Virtuoso Team Colleague
std::string s(itoa(x, buf, 10));
		s += ", ";
		s += itoa(y, buf, 10);;

Read the specification for atoi .

What is the meaning of this cast?

int x = ((int)(short)LOWORD(lParam));

Just using

WORD x = LOWORD( lParam ) ;

will work.

WolfPack 491 Posting Virtuoso Team Colleague

Try only this

Node array[DEPTH][ROW][COL];
WolfPack 491 Posting Virtuoso Team Colleague

This is not a programming solution, but rather a Windows Administrative Solution. But this may be easier than programming the whole thing.

Search for the RemoteAccess Entry in your SystemEvent Log.

Control Panel --> Administrative Tools --> Event Viewer-->SYstem Log

You will be able to filter what you want and save it.
Refer this

Hope this helps.

WolfPack 491 Posting Virtuoso Team Colleague

You better read about local variables, glodabl variables, and passing arguments to functions.

Here is a corrected version.

#include <iostream>
using namespace std;
// This program takes the numerical score and outputs a letter grade.//
int getScore ()
{
[INDENT]int count;
int score,

cout << "\nEnter the student's score: "<< endl;
cin >> score
cout <<"\nThe score is/are: " << score << endl;
return score;[/INDENT]
}



int printGrade( int grade)
{
[INDENT]if ( grade >= 90)
[INDENT]cout <<"\nYour grade is A." << endl;[/INDENT]
else if (grade >= 80 )[INDENT]cout <<"\nYour grade is B." << endl;[/INDENT]else if (grade >= 70 )[INDENT]cout <<"\nYour grade is C." << endl;[/INDENT]else if (grade >= 60 )[INDENT]cout <<"\nYour grade is D." << endl;[/INDENT]else[INDENT]cout <<"\nYour grade is F." << endl;[/INDENT]return 0;[/INDENT]}

int main ()
{
[INDENT]for ( int i = 0 ; i < 10 ; i++ )
{
[INDENT]int num = getScore ();
printGrade(num);[/INDENT]
}
return 0;[/INDENT]
}
WolfPack 491 Posting Virtuoso Team Colleague

Edit this

for ( int i =numlist - 1 ; i>=0; i--)
{
	cout << num[ i ] << endl;
}

to this

for ( i =numlist - 1 ; i>=0; i--)
{
	cout << num[ i ] << endl;
}
WolfPack 491 Posting Virtuoso Team Colleague

Pity that it didnt work for you. I just did a test and it worked for me. I edited the code after posting it the first time. Did you update it accordingly?

WolfPack 491 Posting Virtuoso Team Colleague

Modify your WM_CTLCOLOR Handler as below.

HBRUSH CBKColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
	pDC->SetBkMode( TRANSPARENT) ;
 	return (HBRUSH)(brush->GetSafeHandle());
}
WolfPack 491 Posting Virtuoso Team Colleague

Yeah. Stupid of me for not explaining. Sorry about that. Here is a simple version without using a Summarization Function.

See if you understand it.

#include <iostream.h>

struct program
{
	int employee_id;
	int salary;
	int eval;
	char name[30];
};

// Use constants for Arrays Sizes like below.
const int NUMBER_OF_EMPLOYEES = 2;
const int NUMBER_OF_PERFORMANCE_LEVELS = 4;
main()
{
	int i,j;
	float sal[NUMBER_OF_EMPLOYEES];
	float new_salary(float,int);

	float sum_perform[NUMBER_OF_PERFORMANCE_LEVELS]= { 0, 0, 0, 0 };
	float TotalSalary[ NUMBER_OF_PERFORMANCE_LEVELS ] = { 0, 0, 0, 0 };
	int Count[ NUMBER_OF_PERFORMANCE_LEVELS ] = { 0, 0, 0, 0 };
	/* float summarization( float,int); No need for this function*/

	program employee[ NUMBER_OF_EMPLOYEES ];
	

	for (i = 0; i<NUMBER_OF_EMPLOYEES;i++)
	{
		cout<<"Enter your employee name: ";
		cin>>employee[i].name;

		cout<<"Enter your employee identification number: ";
		cin>>employee[i].employee_id;

		while( employee[i].employee_id > 9999)
		{
			cout<<"ERROR!! Please enter ID again\n";
			cout<<"Enter your employee identification number: ";
			cin>>employee[i].employee_id;
		}

		cout<<"Enter current annual salary: ";
		cin>>employee[i].salary;

		cout<<"Enter result of supervisor evaluation: \n"
		 <<"    1. Superior Performance.\n"
		 <<"    2. Above Average.\n"
		 <<"    3. Average.\n"
		 <<"    4. Below Average.\n"
		 <<"     Enter rating between 1 - 4 : ";
		cin>>employee[i].eval;

		while(employee[i].eval<1 || employee[i].eval>4)
		{
			cout<<"ERROR!! Please enter result of supervisor evaluation again";
			cout<<"Enter result of supervisor evaluation: \n"
				 <<"    1. Superior Performance.\n"
				 <<"    2. Above Average.\n"
				 <<"    3. Average.\n"
				 <<"    4. Below Average.\n"
				 <<"     Enter rating between 1 - 4 : ";
			cin>>employee[i].eval;
		}

		sal[i]  = new_salary(employee[i].salary, employee[i].eval);
		
		TotalSalary[employee[i].eval - 1 ] += sal[i] ; // The Total Salary for a Performance Level
		Count[ employee[i].eval - …
WolfPack 491 Posting Virtuoso Team Colleague

What happens when you change your code to this?

char	buf[512] = "";
CSocket tsock;
if ( hsock.Accept(tsock) == 0 )
{
[INDENT]// Error
return;[/INDENT]
}
while (1) 
{[INDENT]int bytes = tsock.Receive(buf,sizeof(buf),0);
if ( bytes == 0 ) // No data read. Close the Socket.
{
[INDENT]break;[/INDENT]
}
if ( bytes == SOCKET_ERROR )
{
[INDENT]AfxMessageBox("Error";
break;[/INDENT]
}
AfxMessageBox(buf);[/INDENT]}
tsock.Close();
WolfPack 491 Posting Virtuoso Team Colleague

Oh Okay. i think I get what you mean.
You want the average salaries the Superior Level workers worked, and so on?
Then make a small change to your summarization function.

int summarization(program EmpArray[],const  int NumberOfEmps)
{
	float Total[ 4 ] = { 0, 0, 0, 0 };
        int Count[ 4 ] = {0, 0, 0, 0 };
	for ( int i = 0 ; i < NumberOfEmps; i++ )
        {
                  Total[ EmpArray[ i ].eval - 1 ] += EmpArray[ i ].salary;
                  Count[ EmpArray[ i ].eval - 1] += 1;
         }
        if ( Count[ 0 ] != 0 )
        {
                    cout << "Avg Sup Level Salaries = " << ( Total[ 0 ] / Count[ 0 ] << endl ;
         }
         if ( Count[ 1 ] != 0 )
        {
                    cout << "Above Avg Level Salaries = " << ( Total[ 1 ] / Count[ 1 ] << endl ;
        }
        // So on until Count[ 4 ]
        return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

Welcome to Daniweb. Regarding your Summarization Function,

float summarization(float n, int b)
{
	float sum = 0;
	int count = 0;
	if(b == 1)
	{
		sum += n ;
		count++; 
	}
	else if(b == 2)
	{
		sum += n ;
		count++; 
	}
	else if(b == 3) 
	{
		sum += n ;
		count++;  
	}
	else if(b == 4) 
	{	
		sum += n ;
		count++;  
	}

	return sum/count;
}

I see that what ever the value of b , the operation is the same.
i.e.

sum += n ;
		count++;

And as the initial values of sum and count are 0, the function can be simplified as follows.

float summarization(float n, int b)
{
         if(b >= 1 && b <=4 )
	{
	        return n;
	}
	else
	{	
                   // Error
                   return 0;
	}
}

What do you exactly mean by

summarized by perfromance error

WolfPack 491 Posting Virtuoso Team Colleague

To Change the Background color do this.
Add a protected variable of type CBrush to the Dialog.

e.g.

protected:
	HICON m_hIcon;
	CBrush *brush;

In your Dialog's OnInitDialog function do this intialization.

// TODO: Add extra initialization here
	brush = new CBrush(RGB(0,0,0));

Add a new Handler for the WM_CTLCOLOR event of the Dialog box.
Right click the dialog.
Select Events.
Double CLick WM_CTLCOLOR in the "New Windows Messages/Events" WIndow and select Add Handler and Edit.

At the OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) Function do this.

HBRUSH CBKColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
 		pDC->SetBkColor(RGB(255, 0, 0));
 		return (HBRUSH)(brush->GetSafeHandle());
}
WolfPack 491 Posting Virtuoso Team Colleague

Could you please post the code? I usually dont like running other people's exe files.

WolfPack 491 Posting Virtuoso Team Colleague

Hello Kitty,

can you help with with my array question? I need to store the users input into an array, then sum the numbers and then print them out in reverse.

Judging by the date this thread was initiated, my guess is that KittyGirl became a KittyWoman, met a CatMan, GotMarried, had maybe a couple of KittyKids and is long gone by now.