|
Ok this is a just a remake of the piece of source that has the problem..
char somthing[200];
char somthing2[200];
cin>>somthing;
cin>>somthing2;
cout<
|
|
|
|
|
Works for me. the only thing is that because you are not outputting newlines the output was "hellohi", as expected.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Given the following:
string Part = “*(-2)”
char buf[5] = “10”
string Result = buf after arithmetic defined in Part is performed
I need to isolate the value after “-“ in Part and perform the arithmetic on buf (knowing in advance that this is a subtraction): For example, using the string values above (pseudo-code):
1- Isolate the “2” in string Part
[actually isolate everything between the “-“ and “)”]
2- Perform the subtraction buf – 2
3- Store result in Result string
Therefore the result should be Result = 8 (10 – 2 = 8)
I need a way to perform these steps….
Any clues or help would be greatly appreciated.
Thanks,
|
|
|
|
|
|
[actually isolate everything between the “-“ and “)”]
If this is exactly what you want, and you don't expect variations, then the following should do:
int x;
sscanf(Part.c_str(),"*(-%d",&x);
But if you wish your program to handle reasonably arbitrary arithmetic expressions the task is not that easy, you'll be basically building an expression parser.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Given string Part = “*(X2)” [multiplication]
I use the following code to extract the “2” into integer arith:
scanf(Part.c_str(),"*(X%d",&arith);
For the addition [“*(+2)”] and subtraction [“*(-2)”] this works perfectly.
However with the multiplication [“*(X2)”] arith is evaluated to be 0 instead of the expected “2”. I also tried using Part = “*(*2)” [this was my first choice] and it does the same thing. Any clues or recommendation?
The exact same problem occurs when trying to implement the Divide [Part = “*(|2)”].
Arith is evaluated to be 0 instead of the expected 2.
Why does it only work for my add [+] and subtract [-] and not my multiply [*] and divide [|]?
|
|
|
|
|
I am trying to always print in Landscape mode regardless of what user chooses. This is my code:
PRINTDLG pd;
LPDEVMODE pDevMode;
pDevMode=NULL;
pDevMode = (LPDEVMODE)::GlobalLock(pd.hDevMode);
// set orientation to landscape
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
pd.hDevMode = pDevMode;//Not needed
::GlobalUnlock(pd.hDevMode);
But it is not working. It always prints whatever user sets in PRINTDLG.
Any help will be appreciated.
Thanks to all.
Joe,
|
|
|
|
|
First off, this is a bad idea. If you want to always print in landscape then you are better off using a custom template and removing the portrait/landscape option from the dialog. Your users will get very PO'd if they choose portrait and it comes out landscape.
Now for your problem: Where have you inserted this code, because I do not see where you call the PrintDlg function. You should set the orientation to what you want after the dialog has been called and returned, if you call it before, then the dialog will override whatever settings you set.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks for repsonding.
I did call it right after it had returned:
memset( &pd, 0, sizeof(PRINTDLG) );
// other init stuff
//then
if( !PrintDlg(&pd)) return 1;
// then I had here that code here...
// landscape mode .. etc
Joe,
|
|
|
|
|
The next thing is does the printer support landscape printing, and if it does, is the DM_ORIENTATION bit flag of the dmFields member set?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I did check this: pDevMode->dmOrientation, and its value is =2 which is the value of DMORIENT_LANDSCAPE.
I know that pd.hDevMode is local but this is why I had this line:
pd.hDevMode = pDevMode;
Joe,
|
|
|
|
|
Anonymous wrote:
pd.hDevMode = pDevMode;
I think that is your problem, remove that line. You are assigning a pointer to a handle and that does not work.
If removing that line does not help, then post the entire code for the function. The initialization of the PRINTDLG structure, the call to PrintDlg, your changing the orientation, and how you access the PRINTDLG structure when you do the actual printing. Somewhere in there you are making a mistake, and I can not figure it out with the limited information you have given so far.
ps. I have to go, so it will be several hours before I will get back to this. Others feel free to help;)
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Here is the code:
static LPDEVMODE pDevMode;
static PRINTDLG pd; // for PrintDlg()
static DOCINFO di;
// Set Up PRINTDLG Structure For PrintDlg()
memset( &pd, 0, sizeof(PRINTDLG) ); // Clear It
pd.lStructSize = sizeof(PRINTDLG); // Size
pd.hwndOwner = this->GetSafeHwnd();
pd.nFromPage = 1;
pd.nToPage = 1000;
pd.nMinPage = 1;
pd.nMaxPage = 1000;
pd.Flags = PD_RETURNDC | PD_PAGENUMS | PD_NOSELECTION | PD_HIDEPRINTTOFILE;
if( !PrintDlg(&pd)) return 1;
// landscape mode
pDevMode=NULL;
pDevMode = (LPDEVMODE)::GlobalLock(pd.hDevMode);
// set orientation to landscape
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
//pd.hDevMode = pDevMode;//Not needed
// Here is code for stuff to print...
// At end is the clean-up
::GlobalUnlock(pd.hDevMode);
Maybe the problem is that pDevMode is local variable, maybe I need to change some global variable, I just do not know what or how.
By the way I commented that line and it had no effect.
Thanks.
Joe,
|
|
|
|
|
Anonymous wrote:
// Here is code for stuff to print...
Ok, that's cool, but this doesn't help me any.
How are you applying your changes to the printer device context? You are using the PD_RETURNDC flag, so I am assuming that you are using the hDC member of the PRINTDLG structure as your printer DC. After you change the orientation, are you calling ::ResetDC(pd.hDC, pDevMode); ? If so, what is the return value, does ResetDC succeed?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Call pDC->ResetDC(pDevMode) after pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
Lisoft
|
|
|
|
|
I added: dc.ResetDC(pDevMode);
and it still prints portrait instead of landscape.
Joe,
|
|
|
|
|
The ResetDC() will not run properly on Windows 98 or lower version of windows
try Windows 2000 or later.
|
|
|
|
|
I have Window xp. VC++ 7.0.
Joe,
|
|
|
|
|
Tye to use the following code to set printer default:
PRINTDLG m_pd;
if (AfxGetApp()->GetPrinterDeviceDefaults(&m_pd))
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(m_pd.hDevMode);
pDevMode->dmOrientation=DMORIENT_LANDSCAPE;
::GlobalUnlock(hDevMode);
}
Lisoft
|
|
|
|
|
I tried this code, but it still prints portrait. I then added: dc.ResetDC(pDevMode);
just after: pDevMode->dmOrientation=DMORIENT_LANDSCAPE;
and it still not printing landscape.
Are there some library files that I have to include?
Never got any warning during compilation.
Joe,
|
|
|
|
|
When I compile any of mine projects with MS Visual C++ 6.0 there is alot of trash inside .exe file. Its looking like debug information although I'm building a release version (there are lots paths and filenames inside executable clearly viewable). How to remove it all, to reduce .exe size ? Why is it there ?
|
|
|
|
|
Exactly how are you viewing the .exe? with a hex viewer? I know that you can still usually find strings in most .exe's using the Win32 disassembler, (I think that's how some people find a message like "you have entered an invalid code" and use a hex viewer to change the 'jmp' statement to a 'nop'... or so I hear ).
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Yup I view it with hexviewer, but i bet it is visible with notepad too
Yea you can crack programs by hexviewers, but disassemblers / hexview+dissaembler (like HIEW or DN) are better, trust me.
But anyhow, question is how to compile without the trash ? Now anyone can see my developement directories, and it grows my .exe too much. Is there some compiler switch or something ?
|
|
|
|
|
Yes, you need to disable the inclusion of the information for the PDB files.
Go to the Project menu and select settings.
A tabbed dialog called 'Project Settings' appears.
Make sure, on the left, the 'settings for' is set to something like "Win32 Release".
Go to tab marked 'Link'.
In 'Category' drop list box select 'Debug'.
Under 'Debug Info' group, make sure the 'Debug Info' check box is NOT checked.
Go to the 'C/C++' tab.
In 'Category' drop list box select 'Preprocessor'.
In the edit field 'Preprocessor definitions' make sure you see NDEBUG. If it is missing, then add it to end of list of other options. If you see DEBUG or _DEBUG in the list of items, then remove it.
That should help.
|
|
|
|
|
Thank you, but actually it didnt, because all those things were like that from the start, those are default Release settings.
|
|
|
|