Thread: [Dev-C++] Simple formatted output question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Scott W. <se...@al...> - 2002-11-07 02:31:20
|
Hi, This is a "C" question (not C++). When printing a number in exponential format (%e) using printf or one of its friends, three digits are used for the exponent: 1.2345e+006. I would like to change this behavior so that the exponent only uses as many digits as it needs: 1.2345e+6 I've looked, but this feature does not appear to be built into any of the format modifiers/switches. Am I missing something and/or is there an easy way to do this? Thnx, Scott |
From: Luigi S. <gi...@li...> - 2002-11-09 03:57:42
Attachments:
arch.tar.gz
|
On Wed, Nov 06, 2002 at 09:31:50PM -0500, Scott Williams wrote: > Hi, > > This is a "C" question (not C++). When printing a number in exponential > format (%e) using printf or one of its friends, three digits are used for > the exponent: > > 1.2345e+006. > > I would like to change this behavior so that the exponent only uses as many > digits as it needs: > > 1.2345e+6 > > I've looked, but this feature does not appear to be built into any of the > format modifiers/switches. Am I missing something and/or is there an easy > way to do this? > > Thnx, > Scott > Hi, Scott Assuming that by "C" you mean C89, the answer is: you are right, there seems to be no built-in way to achieve what you are looking for. However, an easy (probably too simple?) solution could be: - print the value into a string using scientific notation - erase unwanted extra leading zeroes in the exponent To better show the point, I attached an archive with: - a simple implementation of the above function - a short program to test the function - a file with some values I used for the test -- >> gisan >> So you're back... about time... |
From: Phil <tsy...@ya...> - 2002-11-09 05:22:49
|
Hello all, An other newbie question. I have a window (text area) created as follow : g_hRead = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT" , "INPUT", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_CAPTION, 0, 200, 500, 425,hMainWindow,(HMENU)IDC_MAIN_INPUT, GetModuleHandle(NULL),NULL); This window is a "read only" area for the user, i.e. I do not want the user to be able to enter any text in it. The displayed datas (alphanums) are coming from an other process , char by char. I want to display the datas as soon as they are coming in, w/o loosing the ones yet displayed (auto-scroll). The input volume of datas can be of any length (more than one visible window) and the user should be able to save the whole datas into a file on disk at any moment (but then the data input is stopped). Is there any other way (more efficient) than using SetWindowText every time I have an input (which occurs 2-3 times per second) ? Alternate way I tried w/o success : writing the datas on the fly in a file opened as "SHARE" by my soft. Opening it agn for reading (to do a global SetWindowText) does not help and the reading is done only when the writing channel is closed. What's the hint to really have a shared access to the file within the same process ? OS used: Win2000 + Dev-C++ 4.9.6.7, Win32GUI compiled as C++ Thanks for helping. Phil. __________________________________________________ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 |
From: Abhijit S. <mu...@gm...> - 2002-11-10 08:34:48
|
Greets, Phil. > This window is a "read only" area for the user, i.e. I > do not want the user to be able to enter any text in > it. Use the ES_READONLY style flag. > The displayed datas (alphanums) are coming from an > other process , char by char. > I want to display the datas as soon as they are coming > in, w/o loosing the ones yet displayed (auto-scroll). > The input volume of datas can be of any length (more > than one visible window) and the user should be able > to save the whole datas into a file on disk at any > moment (but then the data input is stopped). > Is there any other way (more efficient) than using > SetWindowText every time I have an input (which occurs > 2-3 times per second) ? This is the only way I know. One more thing you can do is save the input data into a temporary buffer and update it only when the buffer is full, after which you can reset the buffer. This reduces the frequency and number of calls to SetWindowText(). When you want the text later, call GetWindowText(). > Alternate way I tried w/o success : writing the datas > on the fly in a file opened as "SHARE" by my soft. > Opening it agn for reading (to do a global > SetWindowText) does not help and the reading is done > only when the writing channel is closed. What's the > hint to really have a shared access to the file within > the same process ? There's no point opening the file for sharing in the same process. You can as well create a RAM buffer, which will be faster and more efficient. If you still want to use a file, you can try calling FlushFileBuffers(). ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |
From: Phil <tsy...@ya...> - 2002-11-10 19:22:56
|
Hello Abhijit, Many thanks for your answer. >Use the ES_READONLY style flag. Yep, Well, in fact with the WS_CAPTION, it is OK also to be "read only", which gives me also a text-bar. But tnx for the info. As for the displayed datas, I need them to be displayed as soon as they are received. So I have to call SetWindowText() for each received data. Well, I can save 50% of the calls, the user will hardly see the difference in getting each info / 0.5 second or 2 infos/second ;o) Now, using WriteFile() and SetWindowsText(), I have noticed something strange abt the '\n', which is saved as "non-displayable" by WriteFile. If I write my file via WriteFile, then the text file loaded to my text area (via SetWindowsText) does not include the "CR" as wanted but a "non-displayable" char. Same behaviour when I display my buffer directly to the text area via SetWindowsText(). When I write my text file (same buffer) via the usual fprintf()/fputs(), then the '\n' is OK and SetWindowsText displays it the way I want. I can not find out the good option/flag to get '\n' as a "good" CR :o( Well, anyway tnx again for your help, very useful and appreciated indeed ! Phil. PS: As I am a subscriber to this list (!), I get your answer via the list _too_ ;o) FWIW & no hurt. __________________________________________________ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 |
From: Carlos d. M. <cg...@wo...> - 2002-11-11 10:50:33
|
When using WriteFile you must change '\n' to "\r\n" (Line Feed + Carriage Return) Phil escribi=F3: > Hello Abhijit, > > Many thanks for your answer. > > >Use the ES_READONLY style flag. > > Yep, Well, in fact with the WS_CAPTION, it is OK also > to be "read only", which gives me also a text-bar. > But tnx for the info. > > As for the displayed datas, I need them to be > displayed as soon as they are received. So I have to > call SetWindowText() for each received data. Well, I > can save 50% of the calls, the user will hardly see > the difference in getting each info / 0.5 second or 2 > infos/second ;o) > > Now, using WriteFile() and SetWindowsText(), I have > noticed something strange abt the '\n', which is saved > as "non-displayable" by WriteFile. If I write my file > via WriteFile, then the text file loaded to my text > area (via SetWindowsText) does not include the "CR" as > wanted but a "non-displayable" char. Same behaviour > when I display my buffer directly to the text area via > SetWindowsText(). > When I write my text file (same buffer) via the usual > fprintf()/fputs(), then the '\n' is OK and > SetWindowsText displays it the way I want. > I can not find out the good option/flag to get '\n' as > a "good" CR :o( > > Well, anyway tnx again for your help, very useful and > appreciated indeed ! > > Phil. > > PS: As I am a subscriber to this list (!), I get your > answer via the list _too_ ;o) > FWIW & no hurt. > > __________________________________________________ > Do you Yahoo!? > U2 on LAUNCH - Exclusive greatest hits videos > http://launch.yahoo.com/u2 > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |