Click here to Skip to main content
15,891,529 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to creat exe files? Pin
gamitech17-Nov-04 10:56
gamitech17-Nov-04 10:56 
GeneralRunning main() from a dialog-based control Pin
aaadetos13-Nov-04 9:30
aaadetos13-Nov-04 9:30 
GeneralRe: Running main() from a dialog-based control Pin
aaadetos13-Nov-04 12:55
aaadetos13-Nov-04 12:55 
GeneralRe: Running main() from a dialog-based control Pin
John R. Shaw13-Nov-04 16:58
John R. Shaw13-Nov-04 16:58 
GeneralRe: Running main() from a dialog-based control Pin
aaadetos14-Nov-04 16:16
aaadetos14-Nov-04 16:16 
GeneralRe: Running main() from a dialog-based control Pin
John R. Shaw17-Nov-04 7:39
John R. Shaw17-Nov-04 7:39 
GeneralRe: Running main() from a dialog-based control Pin
aaadetos19-Nov-04 21:39
aaadetos19-Nov-04 21:39 
GeneralRe: Running main() from a dialog-based control Pin
John R. Shaw20-Nov-04 11:03
John R. Shaw20-Nov-04 11:03 
Remeber a computer is a stupid machine, it does exactly what you tell it and nothing more. Well ok, since we are using libraries written by other peaple, there is a certain level of trust required.

I am still suprised your code compiles at all, let alone runs without crashing.

1) You have introduced a new magic number (extern int K;), do to how you are using it the value of K must be in the range 0-99. (MAGIC NUMBERS ARE BAD AND DANGERIOUS)

2) You have added a new prototype repressenting the same function, but still do not call it. (It does not look like it would do anything any way).
// both of these prototypes (basicaly) mean the same thing.
extern double pressure(double x);
double pressure(double x);

--------------------------------------------------------------------------
Here is what you are telling the computer to do:

1) You open the file and read data in (while praying that K < 100). Then you proceed to ignore the data you just read from the file.

2) You open a file for output. Then you write one word to it "Pressure\n" follow by anouther magic number press. If you read this new file into a string buffer the string would consist of the following: "Pressure\n?" (where '?' is magic number).

3) Show a message box saying the file was generated.

--------------------------------------------------------------------------
Lets analyze the problem:

1) The file consist of two lines of informaional text followed by zero or more lines of numerical data. This implies we may need a variable size array to store the numerical data, unless an maximum size is specifed.
Note: To keep it simple we'll assume maximum array size of 100.

2) The numerical (text) data per line consist of 3 interger values and 3 floating point values no more no less. This implies a record of numerical data stored in a text format, which needs to be translated into a binary format.
// structure representing a binary data record
struct tagMyDataRecord { int H_ft, kh_md, kv_md; float visc_cp, por, ct_psi; };
// a simple array of data records
tagMyDataRecord recArray[100];
// reading data members
inputdeck>>recArray[i].H_ft>>recArray[i].kh_md>>recArray[i].kv_md>>recArray[i].visc_cp>>recArray[i].por>>recArray[i].ct_psi;

3) Once the data has been loaded we to analyze it and output the results to a file. Now since the given code does not analyze the data nor calls any function to do it, I'll assume that all the data is required to produce a single floating point value.

--------------------------------------------------------------------------
Here is rewrite of your code that should work, provided that complete the pressure() function:
// structure representing a binary data record
struct tagMyDataRecord { int H_ft, kh_md, kv_md; float visc_cp, por, ct_psi; };

double pressure(tagMyDataRecord* precArray, int nSize)
{
	double RetValue = 0.0; // needed to hold result
	for( int i=0; i<nSize; ++i )
	{ /* do your calculations in this loop */ }
	return RetValue;
}

void CKuchukDlg::OnAnalyze() 
{
	// Try to open inupt file
	ifstream inputdeck;
	inputdeck.open("input.txt", ios::in);
	
	if (inputdeck.fail())
	{
		//cout<<"Error With Files!";
		AfxMessageBox("Error: Could not open data file!", MB_ICONSTOP);
		return; // we cann't do any thing else
	}	

	// Skip title lines
	inputdeck.ignore(60, '\n');
	inputdeck.ignore(60, '\n');
	
	// Read numaric data from file
	int recCount = 0;
	tagMyDataRecord recArray[100];
	while( recCount < 100 && !(inputdeck.fail() || inputdeck.eof()) )
	{
		inputdeck>>recArray[i].H_ft>>recArray[i].kh_md>>recArray[i].kv_md;
		inputdeck>>recArray[i].visc_cp>>recArray[i].por>>recArray[i].ct_psi;
		++recCount;
		
	}
		
	if (inputdeck.fail())
	{
		AfxMessageBox("Error: Data file read!", MB_ICONSTOP);
		return; // we cann't do any thing else
	}

	// Process data
	double result = pressure(recArray, recCount);
	if (!result)
	{
		AfxMessageBox("Warning: Pressure = 0.0, this may be an error!", MB_ICONSTOP);
	}

	// Open output file
	ofstream outputdeck;
	outputdeck.open("output.txt", ios:out);
	
	if (ofstream.fail())
	{
		AfxMessageBox("Error: Could not open output file!", MB_ICONSTOP);
		return; // we cann't do any thing else
	}	

	// Copy results to output file
	outputdeck<<"Pressure"<<press<<endl;
	AfxMessageBox("Output file Generated!", MB_ICONINFORMATION|MB_OK);
}



INTP
GeneralCEdit subclass question Pin
nguyenvhn13-Nov-04 6:48
nguyenvhn13-Nov-04 6:48 
GeneralRe: CEdit subclass question Pin
BlackDice13-Nov-04 11:39
BlackDice13-Nov-04 11:39 
GeneralRe: CEdit subclass question Pin
nguyenvhn13-Nov-04 14:46
nguyenvhn13-Nov-04 14:46 
GeneralRe: CEdit subclass question Pin
John R. Shaw13-Nov-04 17:29
John R. Shaw13-Nov-04 17:29 
GeneralRe: CEdit subclass question Pin
Ravi Bhavnani13-Nov-04 23:21
professionalRavi Bhavnani13-Nov-04 23:21 
GeneralCAsyncSocket Question Pin
Rassul Yunussov13-Nov-04 0:01
Rassul Yunussov13-Nov-04 0:01 
Generaltime critical thread Pin
LeeeNN12-Nov-04 20:17
LeeeNN12-Nov-04 20:17 
GeneralRe: time critical thread Pin
Michael Dunn13-Nov-04 5:39
sitebuilderMichael Dunn13-Nov-04 5:39 
GeneralRe: time critical thread Pin
Anonymous13-Nov-04 9:57
Anonymous13-Nov-04 9:57 
GeneralRe: time critical thread Pin
John R. Shaw13-Nov-04 17:49
John R. Shaw13-Nov-04 17:49 
GeneralPostThreadMessage Pin
includeh1012-Nov-04 19:17
includeh1012-Nov-04 19:17 
GeneralRe: PostThreadMessage Pin
peterchen12-Nov-04 19:50
peterchen12-Nov-04 19:50 
Questionemail ? Pin
BaldwinMartin12-Nov-04 18:25
BaldwinMartin12-Nov-04 18:25 
GeneralCTreeCtrl item display limit or multiline Pin
Pakosan12-Nov-04 18:02
Pakosan12-Nov-04 18:02 
GeneralHelp :: can't include afximpl.h in VC++.NET Pin
TooLeeDiN12-Nov-04 17:19
TooLeeDiN12-Nov-04 17:19 
GeneralOpen a specific file in a MFC single document Pin
Iceberg7612-Nov-04 17:05
Iceberg7612-Nov-04 17:05 
GeneralRe: Open a specific file in a MFC single document Pin
pubududilena12-Nov-04 20:36
pubududilena12-Nov-04 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.