WolfPack 491 Posting Virtuoso Team Colleague

No one is gonna write code for him...he need to show some efforts.....

I agree. Dave's method uses a char* for the reversing. All I wanted to know was will that count as a method using extra space or not.

WolfPack 491 Posting Virtuoso Team Colleague

I think he said "without using extra space".

WolfPack 491 Posting Virtuoso Team Colleague

Looks like you have defined i more than once in the same scope( i.e. inside the same {} brackets. ). Check at the line numbers given. Usually compiler errors are easy to handle by the programmer as a good guess of the line numbers in error are also given. Rather than posting them here try to figure that out yourself.

WolfPack 491 Posting Virtuoso Team Colleague

you are using the C language. in C you cant declare the iterator i or j inside the for loop.

do this

int i, j;
for ( i = max( 0, x - 1 ) ; i < min( COLUMN - 1, x + 1 ); i++ )
{
	for ( j = max( 0, y - 1 ) ; j < min( ROW - 1, y + 1 ); j++ )
	{
WolfPack 491 Posting Virtuoso Team Colleague

Look at my occ function. The max and min functions take care of that.

int occ( int Grid[ ROW ][ COLUMN ], int x, int y )
{
	int neighbourCount = 0 ;
	for ( int i = max( 0, x - 1 ) ; i < min( COLUMN - 1, x + 1 ); i++ )
	{
		for ( int j = max( 0, y - 1 ) ; j < min( ROW - 1, y + 1 ); j++ )
		{
			if ( ( x == i ) & ( y == j ) )
			{
				continue;
			}
			if ( Grid[ i ][ j ] == 1 )
			{
				neighbourCount++ ;
			}
		}
	}
	return neighbourCount;
}
WolfPack 491 Posting Virtuoso Team Colleague

Quoted from Wikipedia.

1. Any live cell with fewer than two neighbors dies of loneliness.
2. Any live cell with more than three neighbors dies of crowding.
3. Any dead cell with exactly three neighbors comes to life.
4. Any live cell with two or three neighbors lives, unchanged, to the next generation.

It is important to understand that all births and deaths occur simultaneously. Together they constitute a single generation or, we could call it, a "tick" in the complete "life history" of the initial configuration.

I'm sorry, I just can't seem to understand the occ function's purpose.

Inside the generate( ) function, use occ to calculate the number of neighbours for all the cells in the grid, and according to the rules determine if the cell is dead or alive.
Because all the births and deaths occur simultaneously, dont update the original cell. Make a temporary array of the same dimensions and update the cell corresponding to the one in the original array.

After you have finished doing that to all the cells in the original array, copy the temp array into the original one.

WolfPack 491 Posting Virtuoso Team Colleague

I dont know much on Windows Forms Applications, but at first glance everything looks okay to me. But where do you call the CmdAckTimer->Start() method? Dont you have to call it here?

//
// CmdAckTimer
//
this->CmdAckTimer->Interval = 5000; // 5 sec
this->CmdAckTimer->Tick += new System::EventHandler(this, CmdAckTimer_Tick);
this->CmdAckTimer->Start();

and inside the TimerEventHandler

void Test::CmdAckTimer_Tick(System::Object * sender, System::EventArgs * e)
{
CmdAckTimer->Stop();
txtStats->Text=String::Concat (S"CmdAckTimer->Stop", S"\r\n",txtStats->Text);
txtStats->Text=String::Concat (S"Error: Cmd Ack Timer timed out ", DateTime::Now.ToLongTimeString(),S"\r\n",txtStats->Text);
CmdAckTimer->Enabled = true;
}

Check it out.

WolfPack 491 Posting Virtuoso Team Colleague

Try the GetClientRect method of the CWnd class. However the coordinates are with respect to the FrameWindow. You will need some calculations to get it w.r.t the screen.
GetWindowRect gives the coordinates of the Frame window w.r.t. the screen

WolfPack 491 Posting Virtuoso Team Colleague

Probably you missed some steps in setting up the timer. Give us the steps you carried out upto now. Oh and tell us if it is a MFC or Win32 Application.

WolfPack 491 Posting Virtuoso Team Colleague

Or something similar to this.

int occ( int Grid[ ROW ][ COLUMN ], int x, int y )
{
	int neighbourCount = 0 ;
	for ( int i = max( 0, x - 1 ) ; i < min( COLUMN, x + 1 ); i++ )
	{
		for ( int j = max( 0, y - 1 ) ; j < min( ROW, y + 1 ); j++ )
		{
			if ( ( x == i ) & ( y == j ) )
			{
				continue;
			}
			if ( Grid[ i ][ j ] == 1 )
			{
				neighbourCount++ ;
			}
		}
	}
	return neighbourCount;
}

Check the conditions as your Rows and Columns start from 1 and the arrays begin from 0.

WolfPack 491 Posting Virtuoso Team Colleague

Try this for Windows. It writes itself a Batch File and runs it. After the Exe File is deleted, the batch file also deletes itself. A reboot isnt needed here.

#include <iostream>
#include <fstream.h>
#include <windows.h>
#include <shellapi.h>
int main( int argc, char* argv[] ) 
{
	char ExeFileName[ 260 ] = "";
	char BatFileName[ 260 ] = "";
	strncpy( ExeFileName, argv[ 0 ], strlen( argv[ 0 ] ) + 1);
	strncpy( BatFileName, argv[ 0 ], strlen( argv[ 0 ] ) + 1 );
	char* SlashPos = strrchr( BatFileName, '\\' );
	strncpy( SlashPos, "\\BatFileName.bat", strlen("\\BatFileName.bat" )  + 1  );
	ofstream BatFile(BatFileName);
	BatFile << ":Begin" << "\n";
	BatFile << "del " << ExeFileName << "\n";
	BatFile << "if exist " << ExeFileName << " goto Begin" << "\n";
	BatFile << "del " <<  BatFileName << "\n";
	BatFile.close();
	ShellExecute(NULL, "open", BatFileName, NULL, NULL, SW_HIDE);
	return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

change the headers as

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>

include the following statement after the include statements

using namespace std;

OR
append

std::

before

cout ,endl, setw

.
For ex.

std::cout <<

Put a

std::cin.ignore(  );

before the return statement.

WolfPack 491 Posting Virtuoso Team Colleague

search for the malloc, calloc, realloc functions.

WolfPack 491 Posting Virtuoso Team Colleague

Add the following code at the end of your main function.

cout << "Press any key to continue" << endl;
cin.ignore(2);

This link was posted in a previous thread and it has some other methods, that maybe better than this, so take a look at it.

WolfPack 491 Posting Virtuoso Team Colleague

Could you post your code so that we can see what are the dependencies, if there are any?

WolfPack 491 Posting Virtuoso Team Colleague

Any questions? or is this an example for an implementation of a Binary Tree Traversal?

WolfPack 491 Posting Virtuoso Team Colleague

Thanks a lot.

WolfPack 491 Posting Virtuoso Team Colleague

Looks like you dont have it given by the Visual C++ Compiler. Some old versions of Borland had it. But I dont think not now.

WolfPack 491 Posting Virtuoso Team Colleague

I thought Ive read on several occasions that this should be avoided since it is bad programming

If that is true, accept my appologies. Why is it bad?

WolfPack 491 Posting Virtuoso Team Colleague

For a simple C++ program you should be able to do it even when Visual Studio is not installed in the other machine. Since you have mentioned it as simple C++ program, I assume it is a console program and that you have forgotten to include a cin statement at the end of the program. This makes the output window to close immediately after it finished its operation.

you can also use

system("pause" );

statement before the return statement to make the program pause till you press a key.

WolfPack 491 Posting Virtuoso Team Colleague

I am not a an expert in the Linux programming environment, but here is just a hint. But try using g++ instead of gcc. gcc is usually used for C programs while g++ is used for c++.

WolfPack 491 Posting Virtuoso Team Colleague

Replace setw[ 11 ] with setw(11).

WolfPack 491 Posting Virtuoso Team Colleague

when it comes to my dev-cpp debugger.. when I try to go into debug mode.. I am prompted that, "Your project does not have degubbing information, do you want to enable degubbing and rebuild your project?" I select yes, the code is then recompiled.. and then execution stops. why?

This is because you havent specified that you want debugging information generated for the project. You can set this by
1. Select Project
2. Select Options
3. Select the Compiler Tab from the Dialog Box that appear
4. Select Linker
5. Set "Generate Debugging Information" to Yes

After that set a break point and do Debug. You should be able to debug your project.

for some reason, mvsc++ doesn't even appear to recognize my <windows.h> or StdAfx.. or something.. I've tried to play around with the settings and stuff.. even re-installation does not help..

Seems like you have a serious path misconfiguration. What version of VSC++ are you using? I got the same problem with the Visual Studio 2005 beta. But I could work around that by the information in this link .

WolfPack 491 Posting Virtuoso Team Colleague

If you think that it is a bug in Visual Studio, it is not. Refer the following URL.
#pragma comment

You need to link the wsock32.lib or ws2_32.lib ( Winsock Library ) to use the APIs that are needed for WinSock programming in Windows. Visual Studio by default links the kernel32.lib user32.lib gdi32.lib libraries when you build a project. If you are using other libraries ( e.g. ws2_32.lib, ComCtl32.lib ), you will have to explicitly tell that to the linker.

One way is to use the method you have already used. Other methods are setting the "Additional Libraries Used" field in Project Properties->Linker->Input.

Also you can select add Existing Item to Project and browse for the LIbraries you are using and select them. But this method is not encouraged because this uses Absolute Paths and if you compile it in another machine where the Library Path is different, the linker will fail.

WolfPack 491 Posting Virtuoso Team Colleague

You are welcome. Glad to know that I was of any help. Get those debuggers working. The debugger is a programmer's best friend. Strange that both of the debuggers are not working. Do you KNOW how to work with a debugger? Setting breakpoints, and stepping through code using F10, quick watch and such? Just running in debug mode wont help that much. Better take a look in the net. There are heaps of tutorials on Visual Studio debugging.

WolfPack 491 Posting Virtuoso Team Colleague

Tried running it under a debugger. It terminated when the dialog box was initialized. The position that it crashed was this.

while(Lines[i][j]!=',')
              {
                   j++;
              }

I think the reason is this. When you initialized the window, there are no text strings in the edit box. Remember the return value of EM_GETLINECOUNT cant be less than one.

Return Value

The return value is an integer specifying the total number of text lines in the multiline edit control or rich edit control. If the control has no text, the return value is 1. The return value will never be less than 1.

But the above loop will continue searching until it finds a ',' character. It ran after I made the following change. Check if it agrees with your program logic.

while( Lines[ i ] [ j ] != '\0' && Lines[i][j]!=',' )
              {
                   j++;
              }

Similarly for

while(Lines[i][j]!='-')
              {
                   j++;
              }

I dont see why you would want to process the Editbox input at the WM_PAINT message. Cant you just do it at the WM_COMMAND generated at the press of the AddCount ( ID_PB_ADD ) button?

WolfPack 491 Posting Virtuoso Team Colleague

Well I ran the code, and it compiled and linked just fine. Since you have pasted codes for two files, doublyLinkedList.h and main.cpp in the same code window, I only had to seperate them and compile. Otherthan that I didnt do any changes. THe program ran fine, I entered some integers upto -999 and two lists appeared on the screen. However I got a runtime error in the

void doublyLinkedList<Type>::deleteNode(const Type& deleteItem)

function. Apparently you are accessing an invalid pointer. If you have coded all this in a single file, ( which I dont think you are, but just in case ), break it up and see. If you get a linker error even then, my guess is you have not included a necessary library, but without the missing function name I cant say specifically what.

WolfPack 491 Posting Virtuoso Team Colleague

I have worked with MFC for sometime and then started Windows Programming with the pure C/C++ Code and the Win32 APIs. After that much of the things that were not clear in MFC became easier to understand.
All Win32 and MFC does is handle the Various Windows messages under some Event Handling Function. Once you get to know these events, the names given to the handler functions become clear, and you will see that the names are not that random as it initially seems.

For Example - The Prefix NM will denote Notification Message.
WM = Window Message
TVN_KEYDOWN is a specific window message sent from the TreeView ( Hence the Prefix TV ) and since this is of the form of a WM_NOTIFY Message, the Prefix is TVN. A Programmer who has spent some time in Win32 will know that this notifies when a User presses a key when the TreeView Control has input focus.
Similary if you look up the documentation for NM_CUSTOMDRAW you will understand what are the parameters that are passed in he NMCUSTOMDRAW structure. All depends on what you are conversant with.

Yeah in a way I agree with Daishi in that MFC is not that well structured. But this is not due to its resource editor, but the way it generates the Code. I however think that this can be cleared up to some extent if you did some pure Win32 API Programming.

I dont see why …

WolfPack 491 Posting Virtuoso Team Colleague

I believe you are asking for a way of updating a Caption of a Static Text Label Control ( IDC_STATIC ) which displays the Clock output without using the UpdateData method. You can do this by the use of Control Variables. It is possible to declare a control variable for any control that has a resource ID not equal to IDC_STATIC.
Therefore in the assumed case of a Static label follow the steps below.

1. Rename the Resouce ID of the Label to something other than IDC_STATIC ( say IDC_TIMEDISPLAY )

2. Right click the IDC_TIMEDISPLAY Control and select Add Variable.

3. Add a variable of anyname you prefer ( say m_TimeDisplay ) and of Category equal to Control.

4. At the event you want to update the Labels text, Just call
m_TimeDisplay.SetWindowText( m_DisplayString );

where m_DisplayString is the CString variable you want to be displayed in the caption.

WolfPack 491 Posting Virtuoso Team Colleague

Check these links out. Maybe you can get an idea on how to solve your problem.

URLDownloadToFile
URLDownloadToFile Sample
Implementing the Progress Display

WolfPack 491 Posting Virtuoso Team Colleague

I think I read somewhere that to find out if a number is a prime, you dont have to check dividing upto n-1. Upto squareroot(n) is enough. check it out.

WolfPack 491 Posting Virtuoso Team Colleague

It seems that the problem was with the use of IsDialogMessage( ) in the following loop.

while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		if (!TranslateMDISysAccel(hwndClient, &Msg) && 
			!TranslateAccelerator (hwndFrame, hAccel, &Msg) &&
			!IsDialogMessage( hwndClient, &Msg ))
		{
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}
	}

After I commented it out, the problem with accelerators was gone. But then obviously, I cant move among the child windows of an MDI Child Window without the IsDialogMessage() function. Any recommendations on how to solve this?

WolfPack 491 Posting Virtuoso Team Colleague

Hello,
I am developing an application in Win32, ( No MFC at all ). It is an MDI application, and I am using Keyboard accelerators. The Keys that I have assigned for accelerators are working properly, but when I press something that is not an accelerator, such as Ctrl + F ( which is not an accelerator in my program ), the application freezes. Also I am using the tab key to move between child windows in the MDI child documents, and these are also working properly.

Any idea why this can happen? The code is a bit lengthy so i will not post it. If you can give me any suggestion, that alone will help.

Thanks

WolfPack 491 Posting Virtuoso Team Colleague

Just out of curiosity. What has GTK got over good old Visual Studio in the Windows Environment?

WolfPack 491 Posting Virtuoso Team Colleague

You will have to use a mechanism of your own, like storing the file name and the dates you require to a file. No built in mechanisms in Windows for it.

WolfPack 491 Posting Virtuoso Team Colleague

I think I figured out the problem. It is the File System which makes the stat::a_time come out the same. I found the below in the documentation.

st_atime
Time of last access of file. Valid on NTFS but not on FAT formatted disk drives. Gives the same

Try running this in an NTFS partition, and check the results. Hopefully there will be an improvement in results.

WolfPack 491 Posting Virtuoso Team Colleague

Use buf.st_atime instead of buf.st_mtime. That is the last accessed time. But keep in mind that since you are accessing that file in your program, the result will be the time you run the program. Even if you right click the file in Windows ( at least in my Windows 2000 OS ) and select properties, you will see that the last accessed time is the time you right clicked the file. I dont know anyway of getting around that. I personally think that the last modified time ( buf.st_mtime) is the one that matters the most in your application. But it can be otherwise. Good luck.

WolfPack 491 Posting Virtuoso Team Colleague

There is one in the Windows GDI.

COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);

WolfPack 491 Posting Virtuoso Team Colleague

If you are interested in speed, then I think it is better to use the OpenCV library in sourceforges.net. http://sourceforge.net/projects/opencvlibrary/

There are a lot of built in image processing functions and they also provide good documentation. I have used some of it for image prcessing applications, and found them very fast. You can check the tutorials, especialy the one called http://prdownloads.sourceforge.net/opencvlibrary/ippocv.pdf to get started.

WolfPack 491 Posting Virtuoso Team Colleague
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int main()
{
	char filename[] = "c:\\test.txt";
	char timeStr[ 100 ] = "";
	struct stat buf;
	time_t ltime;
	char datebuf [9];
	char timebuf [9];

	if (!stat(filename, &buf))
	{
		strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime));
		printf("\nLast modified date and time = %s\n", timeStr);
	}
	else
	{
		printf("error getting atime\n");
	}
	_strtime(timebuf);
	_strdate(datebuf);
	printf("\nThe Current time is %s\n",timebuf);
	printf("\nThe Current Date is %s\n",datebuf);
	time( &ltime );
	printf("\nThe Current time is %s\n",ctime( &ltime ));
	printf("\Diff between current and last modified time ( in seconds ) %f\n", difftime(ltime ,buf.st_mtime ) );
	return 0;
}

My Output was
Last modified date and time = 06-04-2005 17:24:12

The Current time is 10:25:53

The Current Date is 06/17/05

The Current time is Fri Jun 17 10:25:53 2005

Diff between current and last modified time ( in seconds ) 6195701.000000

WolfPack 491 Posting Virtuoso Team Colleague

Have you been able to get the dates and times? The thing is that SYSTEMDATE is not in the usual "yy mm dd" format. To display this in the way we all understand, you will have to use GetDateFormat and GetTime Format functions. Better is you give us the code up to where you have got the file times and system times. Then it is easier to narrow out the problem.

WolfPack 491 Posting Virtuoso Team Colleague

Okay here goes. You had got your types mixed up and the casting was not done properly. You had assigned floats to integers there by losing information. Also initialize every variable you define. Otherwise you will have unexpected results. I corrected them and basically got it to work. Also I changed the scanf line too. Yours maybe correct, but I prefer this one.

Here is my code. Compare with your program to see the changes I have made,

#include<stdio.h>
#include<iostream> 
#include<stdlib.h> 
#include<string.h> 
using namespace std;

void main() 
{ 
	int j,k; 
	int a = 0,e= 0,i= 0,o= 0,u= 0;
	float A,E,I,O,U; 
	char word[50]; 


	printf("Enter First string: ");
	cin.getline( word, 50, '\n');

	k = strlen(word); 


	for(j=0;j<=k;j++)
	{ 
		if ('a'==word[j]) 
		a++; 

		if ('e'==word[j]) 
		e++; 

		if ('i'==word[j]) 
		i++; 

		if ('o'==word[j]) 
		o++; 

		if ('u'==word[j]) 
		u++; 
	} 

printf("You Typed: "); 
printf("a:%d\t e:%d\t i:%d\t o:%d\t u:%d\t ", a, e, i, o, u); 


printf("Percantage Of Letter:"); 
A=( ( float )a/k)*100;
E=(( float )e/k)*100;
I=(( float )i/k)*100;
O=(( float )o/k)*100;
U=(( float )u/k)*100;
printf("a: %f\t e:%f\t i:%f\t o:%f\t u:%f\t", A, E, I, O, U); 

}
WolfPack 491 Posting Virtuoso Team Colleague

If you are programming for windows you can use the GetFileTime( ) API to retrieve the Created/LastAccessed/and Last Modified times. These are output in the FILETIME structure, so you will have to use the FileTimeToSystemTime() in order to change the FILETIME structure to a SYSTEMTIME structure.
After that , you can get the current systemtime using the GetSystemTime() and compare this with the times you got for the file.

You can find more in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/time_functions.asp

WolfPack 491 Posting Virtuoso Team Colleague

This reply is a bit late. But I hope maybe somebody else will learn something from it.

The list view control has a default font and this is the same for the column and the items. So to change this I think that you should change the font of the list view to the required font with the attributes set as you want, and then enter the columns. After entering the column you can deselect the font and the default font is back in action. I have not tried it. But as it works for other controls like buttons and such it should work here too.

The meaning of the MSDN quote is that you cant change the allignment of the column with index 0 using LVCFMT_RIGHT or LVCFMT_CENTER. To change its allignment you make the list view control think that its index is not zero. To do this what you first insert a first dummy column. Then you insert your actual first column with index 1. You can change the allignment of the column with index 1. After doing that, you delete your dummy column with index 0. Then the column that you wanted as the first column ( but which you inserted after the dummy column ) will become the first one automatically. Hope you get the idea.

WolfPack 491 Posting Virtuoso Team Colleague

What your professor had in mind apparently was to give you an exercise in Data output and a simple exercise in logical operators ( i.e > , < , == , etc. )

The output of a character in hexadecimal and decimal is okay. But you dont have to input the shortest call by hand. You can tell the program to do find it for you.

for example;

int minimum = -1 ;

cin >> a ;

if ( minimum > a )
minimum = a ;

cin >> b ;

if ( minimum > b )
minimum = b

cin >> c ;
if ( minimum > c )
minimum = c ;
...

so on.

After entering the last input and doing the above comparison with minimum, you will get the minimum of the entered sequence.

Similary for the maximum

if ( maximum < a )
maximum = a ;

....

The average as you may know is the sum of a, b ,c , d .. divided by the count of numbers in the sequence.
if you dont know the count of numbers you will be inputing, use a do-while loop as below

#include <iostream>
using namespace std;

int main ()
{

	int sum = 0 ;
	int count = 0 ;
	int a ;
	cin >> a ;
	int minimum = a ; 
	while …
WolfPack 491 Posting Virtuoso Team Colleague

Hi all,
I joined DaniWeb maybe two days back. And I was thinking of what to say about me, other than I am an alchoholic ( work ). Well I guess I can start off by saying that I do programming for a living and also for leisure. My area of programming is C and C++. Although I have been at it for some time, I cant seem to memorize anything , so I am always searching through to MSDN site. :cheesy: I am also interested in Linux. Hope we can help each other through this site.
Regards.
WolfPack