Re: [Mingw-w64-public] printf(%*.*f,d) broken?
hmm. I got this example from p.85 of howard w sams co.e3 The Waite Group's C Primer Plus User-Friendly Guide to the C Programming Language Revised Edition. ISBN 0-672-22582-4 (MSVC 4.x) I didn't think it was in error. but books could be in error. From: K. Frank kfrank2...@gmail.com To: mingw64 mingw-w64-public@lists.sourceforge.net Sent: Friday, May 9, 2014 5:00 PM Subject: Re: [Mingw-w64-public] printf(%*.*f,d) broken? Hi Jim! On Fri, May 9, 2014 at 5:29 PM, Jim Michaels j...@yoohoo.com wrote: I could not find a good example on this because examples in books are scarce as hen's teeth. search engines ignore the * character and maybe even interpret it like a wildcard. :-/ so examples on the web are out. #include stdio.h int main(void) { double d=1234567890.123456789; int width=7,precision=3;//tried 3 and 9 printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); //generates forever loop of spaces, program hangs. return 0; } I think that you have too few arguments to your printf call. I don't actually know what %*.*f does, but I assume it uses printf arguments to specify the actual format. But (according to my assumption) width=%d, precision=%d has already used up the arguments that %*.*f is expecting. When I change the line printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); to printf(width=%d, precision=%d, d=%*.*f\n, width, precision, width, precision, d); the program works as I would expect, printing out width=7, precision=3, d=1234567890.123 I need to use this. but it seems broken. it just locks up generating spaces no matter what I put in for numbers. I don't think that's right. Jim Michaels ... Good luck. K. Frank -- Is your legacy SCM system holding you back? Join Perforce May 7 to find out: • 3 signs your SCM is hindering your productivity • Requirements for releasing software faster • Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] printf(%*.*f,d) broken?
http://en.cppreference.com/w/c/io/fprintf#Parameters according to this and the old C book I have, printf(%*.*f, width, precision, width, precision, value); is wrong. it should be printf(%*.*f, width, precision, value); see http://stackoverflow.com/questions/16413609/printf-variable-number-of-decimals-in-float From: K. Frank kfrank2...@gmail.com To: mingw64 mingw-w64-public@lists.sourceforge.net Sent: Friday, May 9, 2014 5:00 PM Subject: Re: [Mingw-w64-public] printf(%*.*f,d) broken? Hi Jim! On Fri, May 9, 2014 at 5:29 PM, Jim Michaels j...@yoohoo.com wrote: I could not find a good example on this because examples in books are scarce as hen's teeth. search engines ignore the * character and maybe even interpret it like a wildcard. :-/ so examples on the web are out. #include stdio.h int main(void) { double d=1234567890.123456789; int width=7,precision=3;//tried 3 and 9 printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); //generates forever loop of spaces, program hangs. return 0; } I think that you have too few arguments to your printf call. I don't actually know what %*.*f does, but I assume it uses printf arguments to specify the actual format. But (according to my assumption) width=%d, precision=%d has already used up the arguments that %*.*f is expecting. When I change the line printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); to printf(width=%d, precision=%d, d=%*.*f\n, width, precision, width, precision, d); the program works as I would expect, printing out width=7, precision=3, d=1234567890.123 I need to use this. but it seems broken. it just locks up generating spaces no matter what I put in for numbers. I don't think that's right. Jim Michaels ... Good luck. K. Frank -- Is your legacy SCM system holding you back? Join Perforce May 7 to find out: • 3 signs your SCM is hindering your productivity • Requirements for releasing software faster • Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] printf(%*.*f,d) broken?
this is a copy I pasted from another thread to let you know I got the problem solved. I found code that resolves my issue and I get the formatting I want (which what I really want is a quantity of left-hand-side digits and a qty of right-hand-side digits). printf(precision=%d, d=%*.*f\n, width, precision, d); //generates forever loop of spaces, program hangs. #include cstdio//stdio.h int main(void) { int lhsNumDigits=9, rhsNumDigits=5, width=lhsNumDigits+rhsNumDigits+1, precision=rhsNumDigits; //floats printf(d=%0*.*f\n, width, precision, 55.292); //d=00055.29200 printf(d=%*.*f\n, width, precision, 55.292); //d= 55.29200 //strings too. printf(d=%*s\n, 5, abc); //d= abc printf(d=%*s\n, 5, abcdefghi); //d=abcdefghi return 0; } thanks folks. problem resolved. From: K. Frank kfrank2...@gmail.com To: mingw64 mingw-w64-public@lists.sourceforge.net Sent: Friday, May 9, 2014 5:00 PM Subject: Re: [Mingw-w64-public] printf(%*.*f,d) broken? Hi Jim! On Fri, May 9, 2014 at 5:29 PM, Jim Michaels j...@yoohoo.com wrote: I could not find a good example on this because examples in books are scarce as hen's teeth. search engines ignore the * character and maybe even interpret it like a wildcard. :-/ so examples on the web are out. #include stdio.h int main(void) { double d=1234567890.123456789; int width=7,precision=3;//tried 3 and 9 printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); //generates forever loop of spaces, program hangs. return 0; } I think that you have too few arguments to your printf call. I don't actually know what %*.*f does, but I assume it uses printf arguments to specify the actual format. But (according to my assumption) width=%d, precision=%d has already used up the arguments that %*.*f is expecting. When I change the line printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); to printf(width=%d, precision=%d, d=%*.*f\n, width, precision, width, precision, d); the program works as I would expect, printing out width=7, precision=3, d=1234567890.123 I need to use this. but it seems broken. it just locks up generating spaces no matter what I put in for numbers. I don't think that's right. Jim Michaels ... Good luck. K. Frank -- Is your legacy SCM system holding you back? Join Perforce May 7 to find out: • 3 signs your SCM is hindering your productivity • Requirements for releasing software faster • Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] printf(%*.*f,d) broken?
Hi Jim! On Fri, May 9, 2014 at 5:29 PM, Jim Michaels j...@yoohoo.com wrote: I could not find a good example on this because examples in books are scarce as hen's teeth. search engines ignore the * character and maybe even interpret it like a wildcard. :-/ so examples on the web are out. #include stdio.h int main(void) { double d=1234567890.123456789; int width=7,precision=3;//tried 3 and 9 printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); //generates forever loop of spaces, program hangs. return 0; } I think that you have too few arguments to your printf call. I don't actually know what %*.*f does, but I assume it uses printf arguments to specify the actual format. But (according to my assumption) width=%d, precision=%d has already used up the arguments that %*.*f is expecting. When I change the line printf(width=%d, precision=%d, d=%*.*f\n, width, precision, d); to printf(width=%d, precision=%d, d=%*.*f\n, width, precision, width, precision, d); the program works as I would expect, printing out width=7, precision=3, d=1234567890.123 I need to use this. but it seems broken. it just locks up generating spaces no matter what I put in for numbers. I don't think that's right. Jim Michaels ... Good luck. K. Frank -- Is your legacy SCM system holding you back? Join Perforce May 7 to find out: #149; 3 signs your SCM is hindering your productivity #149; Requirements for releasing software faster #149; Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public