Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ohhh! pretty neat :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

no, but Google is a good place to find out how to do it. :D

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to make the program pause before it exits back to the operating system.

#include <stdio.h>

int main()
{
   system("pause");
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just think about it -- its is nothing more than like passing a variable to any other function

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
      // typecast lpParameter back to desired c++ class
       CIlikerpsChatClientDlg* pDlg = (CIlikerpsChatClientDlg*)lpParameter;
       pDlg->DoSomething();
       // blabla
	return 0;
}
void CIlikerpsChatClientDlg::foo()
{
	DWORD dwThreadID;
	HANDLE hThread = CreateThread(0, //lpThreadAttributes 
		0,	//dwStackSize
		ThreadProc,//lpStartAddress
		this,	// lpParameter 
		0,	// dwCreationFlags 
		&dwThreadID);//lpThreadId 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is the minimum required -- all parameters but two are optional and left 0. On W2K and XP the last parameter can be 0 too, but it comes in useful sometimes.

#include <windows.h>

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{

	return 0;
}

int main()
{
	DWORD dwThreadID;
	HANDLE hThread = CreateThread(0, //lpThreadAttributes 
		0,	//dwStackSize
		ThreadProc,//lpStartAddress
		0,	// lpParameter 
		0,	// dwCreationFlags 
		&dwThreadID);//lpThreadId 

							return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can use strtok() -- warning, that function changes the string, so if you need the original string later in the program you will have to make a copy of it before calling strtok() the first time.

std::string str = "48098, 50933, 3128, 323, 42, 5";
int n;
char* ptr = strtok((char*)str.c_str(),",");
while(ptr != 0)
{
   n = atoi(ptr); // you will probably want to put the ints into 
                     // some sort of array or vector 
   ptr = strtok(0,",");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Most of the parameters to CreateThread are 0 (NULL). The only required parameters are the name of the thread proc and the last one -- pointer to DWORD threadID. I leave all others 0.

The parameter immediately following the thread proc is a parameter you want to pass to the thread -- it can be a pointer to any object or a simple integer. Sometimes I pass the "this" pointer so that the thread will have access to c++ class instance.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ThreadMessages() must be a static method of the c++ class or a global function outside any class. I prefer using CreateThread() because it does not require linking to special multi-threading libraries like _beginthread().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am reading a Java book,.

why would you read a java book to learn c++ :eek: :eek: Does that imply I can learn java by reading a c++ book :?:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

or code as std::string meh = first;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

or use a template?? I'm not very good at them, so don't ask me how.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What about if you pass a long to the function in main?

no problem with that either. why don't you post your program (zip it up first if its pretty long)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might have some other problem. This works ok for me

#include <iostream>
using namespace std;

void foo(const long& l)
{
	cout << l << endl;
}

void foo(const bool& l)
{
	cout << l << endl;

}


int main(int argc, char* argv[])
{
	bool b = true;
	foo(b);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since you didn't post any code we can only guess. sysName is apparently NOT declared in any of the header files that are included in server.cpp. user the extern keyword like below.

// includes.h
[b]extern [/b] char sysName[32];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
CTestClass CTestClass();

The above is not an instance of a CTextClass class but a prototype for a function that returns a CTestClass object.

Please PM me

No. Post your questions so others can learn or answer. I don't do unpaid private tutoring (well, actually, I don't do paid private tutoring either.)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is normal c++ stuff and has nothing at all to do with MFC, other than MFC is also c++. When you put static keyword in the .h file that is making it global with the namespace of the class in which it is defined. So your compiler is producing unresolved error because you didn't actually create an object of that static variable.

you didn't say what variable you made static, so I'll just assume it is named "var". Put this at (or near) the top of the implementation file (*.cpp) -- outside any function, just like you would any other global variable.

CProjectView::var = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't really know a thing about that file, but that sort of error message usually means the file is not in one of the directories in the PATH environment variable. search the hard drive to see if that file was installed. If not, then install it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another way to round (maybe) the internal representation of a float.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes --

vector<string> names;
//
// assumes there are more than 4 names in the vector
sort(names.begin()+1, names.end()-2);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

05/10/2004,00:00:45,190,0,13.94,346.81,206.67,18.46,32,3,47,6, ...

The above is taken from log_05.csv. How is that different from book.csv? The file you posted looks like just trash data, not real data. When your program first opens the file, look at the first line of data. If the first comma-separated field contains a '/' then its a date and the first column number that contains data is #2 (0 is first). If the '/' is not in the first field, then #0 is the first column you want, and subtract 2 from each of the column numbers in array "array".

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the calculation suppose to be right.

Then I would suggest YOU find out what is wrong. Use (or learn to use) you compiler's debugger.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what modifications shd i do

A complete (or nearly complete) rewrite. There could be a port of graphics.h to win32, but I have't heard of any. google around a little to see what you can find there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

because the cout line is printing the value of the loop counter -- i -- not the value of the array, which stores the real column number.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

API (Application Program Inerface) allows your program to access operating system functions, or functions in a library that may have been written by someone else. For example, the functions sleep(1000), a *nix API function, and Sleep(1000), a MS-Windows function (note spelling capatilization differences). They may be implemented in either a DLL (MS-Windows), shared library (*nix version of a dll), or a statically linked library (both MS-Windows and *nix have them).

Short anwer: a DLL contains pre-compiled implementation code for API functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

create an array of ints that contain the column numbers you want, then use that in main().

int array[] = {5,6,15,16,17,22,23,28,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 };

// number of elements in the above array
int arraysize = sizeof(array) / sizeof(array[0]);

			for(int col = 0; col < arraysize; col++)
			   sums[col] += sumcol(array[col],line);

all columns can be sumed as floats whether the data contains integers of floats. atof() will work correctly with both strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes, that was a copy/paste error.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dev-C++ version 4.9.9.2 works ok too. Suggest you upgrade to current version.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

might be your compiler -- mine (VC++ 6.0) prints -133. what compiler are you using?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

...the program sets all elements of the rolls array to 0 (there is a much easier way to do that than is shown in the program.).
How?

Below sets all elements of the array to 0 because if one or more elements are explicitly initialized as shown below, all remaining elements not in the initialization list are set to 0.

int roll[12] = {0};

Finally, the program attempts (incorrectly by the way) to display the results.
What's the corret way.

for (i=2; i<=12; i++)
{printf ("%2d (%3d) : ",i, rolls [i]);

All arrays are numbered from 0 to 1 less than the number of elements. rolls array has 12 elements, which are numbered 0, 1, 2, 3, ... 11. The loop above will attempt to access element number 12, which does not exist.

[edit]Note: Dave fixed the problem by declarin the array to have 13 elements, not 12. [/edit]

This is the correct loop -- it uses < not <=. The i counter initializer may also be wrong, depending on the programmer's intent for the first element. The second array element is numbered 1, not 2.

for (i=2; i<12; i++)
{printf ("%2d (%3d) : ",i, rolls [i]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The random generator parts are ok, there are other problems such as undefined variable names.
[edit]nevermind -- due to its very sloppy programming style I missed a function[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is a pretty sloppy program that was probably written by a 1st semester student that didn't know what (s)he was doing. It contains several problems that will not allow any compiler to successfully compile it. If you are using this as an example to learn -- DON'T.


the program sets all elements of the rolls array to 0 (there is a much easier way to do that than is shown in the program.). Next it generates 1,000 random rolls of the dice and increments the array to count the number of times a roll was generated. Finally, the program attempts (incorrectly by the way) to display the results.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since name is on a separate line, I would use getline() to read the entire line into a temporary string, than parse that string for spaces. std::string has a find function that you can use to get the individual words

#include <string.h>
//
..
string temp;
// read the entire line in the string
getline(input_file,temp);
// get last name
//
// locate the first space that separater last and first names
int pos = temp.find(' ');
// if found, then copy it to destination character buffer
if(pos > 0)
{
   strcpy(last_name,temp.substr(0,pos).c_str());
   // remove last name from the string
   temp = temp.substr(pos+1);
}
// now do the same with first and middle names

or if you want to use c strings for this

char temp[80];
// read the entire line in the string
input_file.getline(temp,sizeof(temp));
// get last name
//
// locate the first space that separater last and first names
char *ptr = strchr(temp,' ');
// if found, then copy it to destination character buffer
if(ptr != 0)
{
   // null terminate the last name portion of temp string
   *ptr++ = 0;
   // bypass all white space to get to the first name
   while(*ptr && isspace(*ptr))
     ptr++;
   // copy last name to final character buffer
   strcpy(last_name,temp);
   // remove last name from the string.  This will move everythnig
  // in the temp string left to write over the last name.
   strcpy(temp,ptr);
}
// now do the same with first and middle names
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please edit your post and enclose the code in code tags. I hope the original program contains proper indentations so you can read it.

[ code ]
// code here
[ /code ]

remove spaces from above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

simply use the col variable number. You can also put that code in another function that takes the column number as a parameter.

int main()
{
int main()
{
	ifstream input_file("filename");
	if ( !input_file.is_open())
	{ 
		cout << "Error opening file.";
	}
	else
	{
		for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
			getline(input_file, line, '\n');
		count = 8;                  // We are in the eighth line
		int col = 5;
		while(count <= 1447) 
		{      // We have to add until 1447 lines..           
			for(int i = 0; i < col; i++)
				getline(input_file, line, ',');    // Get the first 5 columns.
			cout<<line<<endl;       // Print the 5th column for verification.
			value = atof(line.c_str());// Convert the 5th column into float
			sum += value;	//add value to sum
			getline(input_file, line, '\n');    // Go to the next line..
			count++;        // Increment the count, to go to the next line
		}
		cout << count;
		cout<<endl<<"The sum of all values of column 5 is : "<<sum<<endl;
	
		float avg = sum / count ;
		cout<<endl<<"The avg of all values of column 5 is : "<<avg<<endl;   
   }
    
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that loop is supposed to be in firstArray(), not main(). There is a corrected program

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



bool getInputFilename(char fname[])
{
	ifstream fin;

	cout << "Please enter the filename for input : ";
	cin >> fname;
	
	fin.open(fname, ios::nocreate);
	
	if (!fin.is_open())
		return false;
	
	fin.close();
	return true;
}


bool getOutputFilename(char fname[])
{
	ofstream fout;

	cout << "Please enter the filename for output : ";
	cin >> fname;

	fout.open(fname);

	if (fout.fail())
		return false;

	fout.close();
	return true;

}

void firstArray(ifstream& fin, int marks [], char name[])
{
	fin >> name;
	int i = 0;
	while (i < 12 && fin>>marks[i]) {
		i++;
	}
}






void main()
{
	ifstream fin;
	ofstream fout;

	char IFname[20], OFname[20];
	int marks [12], i;
	char name [3];


	while (!getInputFilename(IFname))
	{
		cout << "Invalid filename try again!\n\n";
	}

	while (!getOutputFilename(OFname))
	{
		cout << "Invalid filename try again!\n\n";
	}

	fout.open(OFname);
	fin.open(IFname);

	firstArray(fin,marks, name);


	fout.close();
	fin.close();

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move fin >> name OUTSIDE that loop! there is only one instance of it on a line. that whole look is wrong anyway -- should not use eof() like that because it sometimes produces undesireable results.

fin >> name;
            i = 0;
	while (i < 12 && fin>>marks[i]) {
		i++;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

to this twice (or put in loop that runs until end-of-file

fin >> name;
firstArray(...);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
if (col =5)

you want the boolean == operator, not assignment = operator.

Why do you need those two if statements? With the variable you can combine them and remove if(col == ???)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

make the column number a variable so that you can change it as desired.

int col = 7;
 for(int i = 0; i < col; i++)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In function firstArray() you declared an input stream and an output stream. The output stream is never used, so you might as well delete it. The input stream is never opened, so the loop will always fail.

main() is already opening the input and output streams, so why not just pass the name of the input stream as another parameter to firstArray() function and delete both those stream objects you declared inside that funtion. You will also have to change the code shown in blue below.

void firstArray(ifstream& in, int marks [], int arraySize)
{
...

Then in main(), move that function call to firstArray down after the files are opened, and pass the parameters as shown above.

void main()
{
	ifstream fin;
	ofstream fout;

	char IFname[20], OFname[20];
	int marks [12];
	char name[40];

	


	while (!getInputFilename(IFname))
	{
		cout << "Invalid filename try again!\n\n";
	}

	while (!getOutputFilename(OFname))
	{
		cout << "Invalid filename try again!\n\n";
	}

	fout.open(OFname);
	fin.open(IFname);

	firstArray(fin,marks,12);

//	fout << marks << endl;

     for(int i = 0; i < 12; i++)
          fout << marks[i] << endl;
    

	fout.close();
	fin.close();

}

After opening the files you need to make a sanity check to see if the files were opened ok. Something like this

fin.open(IFname);
   if(!fin.is_open())
  {
     cout << "cannot open file " << IFname << endl;
     return 1;
  }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it does nothing because the function is never called anywhere. And why not use std::string for the file names instead of C style character arrays? If you are writing c++ then use c++ as much as possible. And you should use getline() for entering filenames so that the path and file names can contain spaces.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those are non-standard C functions that are defined in conio.h. Because they are non-standard, they may not be supported by all compilers (I think Dev-C++ supports them)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is there a way to make a MFC application have Network capibilities without using windows sockets?

No. winsock is Microsoft's implementation of Berkley Sockets which is the standard socket library in *nix os.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

this is probably not relivent to this thread -- but here is what I found in MSDN for environment variables

• The maximum individual environment variable size is 8192bytes.

• The maximum total environment variable size for all variables, which includes variable
names and the equal sign, is 65,536KB.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Add c:\Dev-Cpp\bin\ to your path. Reboot.

(But it does appear to find the make utility, which I would assume is in the same directory, so I'm reaching for straws.)

I use XP Pro too.

you might also check the length of the PATH environment variable. On my computer it's so long that there isn't any room left to add more. So I have a batch file to truncate the PATH to bare necessity so that I can run other command-line programs from command prompt.

Look at the end of the PATH as shown in command prompt -- if the last path isn't all there, then you probably have to same problem that I do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>When you install Dev-Cpp, do you need to reboot to update the path?

I think it depends on which version of Windows is running. W2K/XP, definitely not. Win95/98/ME, I'm not sure either (I never used ME)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

might be a dumb question -- but did you check your computer to see if those -I<path> paths actually exist?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to either include the implementation file for Gui class in the dll project, or link with a *.lib file that includes it in either another dll or static library.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>your statement is incorrect across the board. You're mixing up the getline member function provided by std::istream (which uses C-style strings) and the getline function provided for use with std::string in <string>.

I didn't mix them up, nor was it incorrect -- I just mentioned them both in the same breath. I didn't say they were interchangeable, and I actually posted sample code that shows the difference, just like you did.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I stand corrected... brain fart.... howerver, there does happen to be a stdlib.h.

Yes there is -- but its C, not C++. and just look at the copyright dates that you posted, that file is at 8-21 years old! The most recent c++ standard was in (I think) 1998.

C++ system headers do not use .h file extensions. The c++ equivalent is <cstdlib>. If your c++ compiler does not support <cstdlib> then you need to toss that piece of trash into the bit bucket and get a more modern compiler, such as Dev-C++ or any of a number of others.

Your compiler may well compile stdlib.h with no problems -- but you run the danger that it will not contain up-to-date functions that are in <cstdlib>. I know VC++ 6.0/7.0/8.0 cstdlib just simply includes stdlib.h, but that by no means other compiler follow that.