|
From the code that you pasted, I'm not able to figure out what the problem is.
The if condition looks perfect.
Is that on line 34 of main.c?
|
|
|
|
|
Yes. Its line # 34 in main.c
When I remove if statement and just set lStructSize to one of the values, the code compiles perfectly.
|
|
|
|
|
It seems that there is nothing unusual.
Give it a try by changing the name of the function "win98". It might confuse the compiler?
|
|
|
|
|
What does the win98() function do?
|
|
|
|
|
I am trying to sort a list using the insertion sort algo, but my application crashes. I think those pointers lost track by using the remove function. Is there a better way to sort except using the sort() (list.sort() function). It does not work too well with it since I am sorting by Departure Time of the object in the list.
Here is the code i wrote:
//Insertion sort to sort runs by departure time in the Res_RunList
int numruns = Res_RunList.size(); //the size of the list
ListOfRuns::iterator Tempitr1; //create itr poniters to navigate thru the list
ListOfRuns::iterator Tempitr2;
ListOfRuns::iterator Tempitr3;
ListOfRuns::iterator Tempitr4;
ListOfRuns::iterator Tempitr5;
ListOfRuns::iterator Tempitr6;
std::list <RDLRun*> TempList;
ListOfRuns::iterator Tempitr7;
Tempitr1 = Res_RunList.begin(); //points to the 1st element
Tempitr2 = Res_RunList.begin();
Tempitr6 = Res_RunList.begin();
for(int low = 1; low < numruns; ++low)
{
++Tempitr2; //points to low position
RDLRun *TempRun = (*Tempitr2); // store the data from low position in TempRun
int u = low -1;
Tempitr3 = Tempitr2;
Tempitr4 = Tempitr3--; //ponits to u position
//compare the time windows
while(u >=0 && ( (*Tempitr4)->GetDepartureTime() > TempRun->GetDepartureTime() ) )
{
Tempitr5 = Tempitr4;
Res_RunList.insert(Tempitr5++, (*Tempitr4));
Res_RunList.remove((*Tempitr5++));//to prevent duplicate
--u;
--Tempitr3;
}//end while loop
if(u > 0 || TempRun->GetDepartureTime() > (*Tempitr1)->GetDepartureTime())
{ Res_RunList.insert(Tempitr4++, TempRun);
Res_RunList.remove((*Tempitr4++));
}
else{
Res_RunList.insert(Tempitr6++, (*Tempitr1));
Res_RunList.remove((*Tempitr6++)); Res_RunList.insert(Tempitr1, TempRun);
}
}//end for loop
Thanks.
|
|
|
|
|
I don't see you using sort in your code.
Also, any insertion or deletion in the list renders the iterators invalid.
This can give you unexpected results.
|
|
|
|
|
Do you know of any better way to approach this scenario? Sort those objects in acending order by within a list?
Thanks.
|
|
|
|
|
The best approach is to use TempList.sort(MyCompare<RDLRun*>());
Here MyCompare is a functor used to decide how to sort the list of RDLRun class pointers.
|
|
|
|
|
Thanks for the insight. I have create a little functor to work with the sort function but getting an error. there is something that I am not doing right. Thanks for your help.
Functor code:
bool RDLTemporaryResource::SortByTime:public std::binary_function<RDLRun*, RDLRun*, bool>
{
bool operator() (RDLRun* a, RDLRun* b) const
{
if( a->GetDepartureTime() < b->GetDepartureTime() )
return 1;
else return 0;
}
}
Compiler error message:
--------------------Configuration: fstool - Win32 Debug--------------------
Compiling...
TEMPRES.CPP
c:\program files\ilps\code\fstool\tempres.cpp(837) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
fstool.dll - 1 error(s), 0 warning(s)
|
|
|
|
|
Hi
i use ado to get data from database in vc, but now i want to let the data displayed in ms-word ,and then i can print
i just want to use word, no crystal report
pls give me some suggestions or materials
or complete steps to let data displayed in ms-word
i need help
thanks a lot
Sincerely
|
|
|
|
|
1) Write the data to the printer (driver) using code.
2) Write the data to a text file, and use ShellExecute(hWnd, "print", "data.txt", ...) on that text file. This will default to Notepad, but you can specify Winword.exe instead.
3) Use Word Automation.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
An exe uses a dll file.
If only code inside function body of the dll file was changed (no functions were added or deleted and function signitures were not changed), but exe itself was not re-compiled, may the dll cause any dangrous (or problem) for the exe file?
the Q related to software auto-updates.
For lite reason, I don't want to update exe when update dll.
|
|
|
|
|
includeh10 wrote: may the dll cause any dangrous (or problem) for the exe file?
As long as the function signatures which are called by the executable are the same there should be no problems. You can even add resources or additional functions without any problems.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
It is safe to change the internal implementation of the exported functions, as long as you retain the signature. It is also perfectly safe to add more new functions, but you should not remove an existing function that may be used by the executable.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
includeh10 wrote: no functions were added or deleted and function signitures were not changed
Yes that is safe, also see binary compatibility[^] for more background on the topic.
|
|
|
|
|
hello, i am having a problem with this code. I do not know what is wrong. I enter the begbal, the ourdep and the withdraw. But in the end when goes to get the final balance. The answer is always the same as the input of begin bal. Any help would be greatful.
#include <stdio.h>
#define SENTINEL 0
float endbal,
finbal;
int date,
outdep,
withdraw;
int main (void)
{
printf("BANK RECONCILIATION FOR: 10/21/98");
printf("\n\nEnding balance on statement:");
scanf ("%f", & endbal);
printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
scanf ("%d", & outdep);
while (outdep!= SENTINEL)
{
finbal = finbal + outdep;
printf("Enter outstanding dep (%d to quit)>", SENTINEL);
scanf("%f", & outdep);
}
printf("Outstanding check/withdrawal (or %d to quit)>", SENTINEL);
scanf ("%d", & withdraw);
while (withdraw!=SENTINEL)
{
finbal = finbal - withdraw;
printf("Enter withdrawal (%d to quit)>", SENTINEL);
scanf("%f", & withdraw);
}
finbal = endbal + outdep - withdraw;
printf("Your final balance in your checkbook should be $ %f" , finbal);
return 0;
}
|
|
|
|
|
Change
kbury wrote: printf("\n\nEnding balance on statement:");
scanf ("%f", & endbal);
to
printf("\n\nEnding balance on statement:");
scanf ("%f", & finbal);
and then remove the following line
kbury wrote: finbal = endbal + outdep - withdraw;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I made the changes and did the execute, this is what came out. still not the right answer. I do not know what else to do with this. I have tried so many things.
BANK RECONCILIATION FOR: 10/21/98
Ending balance on statement:20
Enter outstanding dep (0 to quit)>10
Enter outstanding dep (0 to quit)>10
Enter outstanding dep (0 to quit)>10
Enter outstanding dep (0 to quit)>0
Enter outstanding dep (0 to quit)>0
Outstanding check/withdrawal (or 0 to quit)>10
Enter withdrawal (0 to quit)>10
Enter withdrawal (0 to quit)>0
Your final balance in your checkbook should be $ 2185232384.000000
"c:\cop2000\a5\lcc2\score.exe"
Return code 0
Execution time 12.438 seconds
Press any key to continue...
|
|
|
|
|
Well, I didn't notice you made a bad mix of floats and ints.
Try
#define SENTINEL 0
int endbal,
finbal,
date,
outdep,
withdraw;
#include <stdio.h>
int main (void)
{
printf("BANK RECONCILIATION FOR: 10/21/98");
printf("\n\nEnding balance on statement:");
scanf ("%d", & finbal);
printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
scanf ("%d", & outdep);
while (outdep!= SENTINEL)
{
finbal = finbal + outdep;
printf("Enter outstanding dep (%d to quit)>", SENTINEL);
scanf("%d", & outdep);
}
printf("Outstanding check/withdrawal (or %d to quit)>", SENTINEL);
scanf ("%d", & withdraw);
while (withdraw!=SENTINEL)
{
finbal = finbal - withdraw;
printf("Enter withdrawal (%d to quit)>", SENTINEL);
scanf("%d", & withdraw);
}
printf("Your final balance in your checkbook should be $ %d" , finbal);
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
kbury wrote: finbal = finbal + outdep;
finbal is an r-value which has not been properly initialized.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
None of the values have been initialized and it always causes problem as the programs works on a random garbage value.
1. endbal is not initialized. Either set it to 0 or some other positive value at the start of your program.
2. finbal must be set to 0 at the start of main() function.
You can initialize these at the time of declaration : float endbal = 0, finbal = 0;
Also the statement finbal = endbal + outdep - withdraw; is wrong. You have already added deposit amount and subtracted withdrawn amount in the variable finbal . So all you need is endbal = endbal + finbal .
Finally, you are displaying the wrong value. You should display endbal in the last printf statement.
I hope this helps you.
modified on Wednesday, October 14, 2009 6:59 PM
|
|
|
|
|
sorry, but that is horrible code.
you have amounts in int and float types, it might be wise and safe to be consistent.
you have an int withdraw yet you fill it with a %f in scanf.
you have two balance variables, you only need one.
you don't initialize variables that need it.
you have duplicated several lines, indicating you have chosen the wrong loop construct (use a do while instead!)
and what happens when the input isn't a number (say an empty line, or some text)?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
modified on Wednesday, October 14, 2009 7:50 PM
|
|
|
|
|
I am still learning. I was not required to write a code for this but just a draw a flowchart. Any pointers would be appreciated.
|
|
|
|
|
Hi,
not tested:
float getNumber(char* prompt, float* delta) {
float number;
printf(prompt);
scanf("%f", number);
... add whatever checking you consider important
*delta=number;
return number!=0;
}
int main(void) {
float balance, delta;
int more;
printf("BANK RECONCILIATION FOR: 10/21/98");
printf("\n\nEnding balance on statement:");
scanf("%f", &balance);
do {
more=getNumber("Enter Outstanding dep (or 0 to quit)", &delta);
balance+=delta;
while(more);
do {
more=getNumber("Outstanding check/withdrawal (or 0 to quit)");
balance-=delta;
while(more);
printf("Your final balance in your checkbook should be $ %f" , balance);
return 0;
}
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Dear Expert,
The following code is for displaying DialIn tab of user object in active directory.
can any one covert this code to visual c++ using adsi
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const FourthOctet = 1
Const ThirdOctet = 256
Const SecondOctet = 65536
Const FirstOctet = 16777216
Set objUser = GetObject _
("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
blnMsNPAllowDialin = objUser.Get("msNPAllowDialin")
WScript.Echo "Remote Access Permission (Dial-in or VPN)"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Control access through Remote Access Policy"
Err.Clear
Else
If blnMsNPAllowDialin = True Then
WScript.Echo "Allow access (msNPAllowDialin)"
Else
WScript.Echo "Deny access (msNPAllowDialin)"
End If
End If
WScript.Echo
arrMsNPSavedCallingStationID = objUser.GetEx("msNPSavedCallingStationID")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No Caller-ID specified."
Err.Clear
Else
WScript.Echo "Verify Caller ID (msNPSavedCallingStationID): "
For Each strValue in arrMsNPSavedCallingStationID
WScript.echo strValue
Next
objUser.GetEx "msNPCallingStationID"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Calling station ID(s) specified but not assigned."
Err.Clear
Else
WScript.echo "Calling station ID(s) assigned."
End If
End If
WScript.Echo
intMsRADIUSServiceType = objUser.Get("msRADIUSServiceType")
WScript.Echo "Callback Options"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No Callback"
Err.Clear
Else
strMsRADIUSCallbackNumber = objUser.Get("msRADIUSCallbackNumber")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Set by caller (Routing and Remote Access Service only)"
Err.Clear
strMsRASSavedCallbackNumber = objUser.Get("msRASSavedCallbackNumber")
If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Unused value of " & strMsRASSavedCallbackNumber & _
" appears in the Always Callback to field."
Else
Err.Clear
End If
Else
WScript.Echo "Always Callback to: " & _
strMsRADIUSCallbackNumber & " (msRADIUSCallbackNumber)"
End If
End If
WScript.Echo
intMsRASSavedFramedIPAddress = objUser.Get("msRASSavedFramedIPAddress")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No static IP address assigned."
Err.Clear
Else
If sgn(intMsRASSavedFramedIPAddress) = -1 Then
intIP = intMsRASSavedFramedIPAddress
WScript.StdOut.Write 256 + (int(intIP/FirstOctet)) & "."
intFirstRemainder = intIP mod FirstOctet
WScript.StdOut.Write 256 + (int(intFirstRemainder/SecondOctet)) & "."
intSecondRemainder = intFirstRemainder mod SecondOctet
WScript.StdOut.Write 256 + (int(intSecondRemainder/ThirdOctet)) & "."
intThirdRemainder = intSecondRemainder mod ThirdOctet
WScript.Echo 256 + (int(intThirdRemainder/FourthOctet))
Else
intIP = intMsRASSavedFramedIPAddress
WScript.StdOut.Write int(intIP/FirstOctet) & "."
intFirstRemainder = intIP mod FirstOctet
WScript.StdOut.Write int(intFirstRemainder/SecondOctet) & "."
intSecondRemainder = intFirstRemainder mod SecondOctet
WScript.StdOut.Write int(intSecondRemainder/ThirdOctet) & "."
intThirdRemainder = intSecondRemainder mod ThirdOctet
WScript.Echo int(intThirdRemainder/FourthOctet)
End If
objUser.Get "msRADIUSFramedIPAddress"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Static IP address specified but not assigned."
Err.Clear
Else
WScript.Echo "Static IP Address assigned."
End If
End If
WScript.Echo
arrMsRASSavedFramedRoute = objUser.GetEx("msRASSavedFramedRoute")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No static Routes specified."
Err.Clear
Else
WScript.echo "Static Routes (msRASSavedFramedRoute):"
WScript.Echo vbTab & "CIDR 0.0.0.0 Metric"
For Each strValue in arrMsRASSavedFramedRoute
WScript.echo vbTab & strValue
Next
objUser.GetEx "msRADIUSFramedRoute"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Static Routes specified but not assigned."
Err.Clear
Else
WScript.echo "Static Routes assigned."
End If
End If
|
|
|
|