![]() |
| | #1 |
| Registered User Join Date: May 2009 Location: Chennai, India
Posts: 17
| Doubt in using % symbol under sprintf I got a requirement of changing the display string in one of the application. It is something like changing "90 percentage CPU" to "90% CPU". First, i did the fix in one of the printf by doing printf("%d\% CPU",per); Then, i need the same changes under sprintf so i tried sprintf(str,"\%%s","CPU"); But, when i tried to print the "str" i am getting the result as %s. So, i searched and found in some forum they suggested to use double % symbol like the following sprintf(str,"%%%s","CPU"); With this change it is correctly printing %CPU. Can someon explain me how this intertpretation works under sprintf? -BalaC- |
| cbalu is offline | |
| | #2 |
| Registered User Join Date: Oct 2008
Posts: 452
| "\%" is wrong. It works here because it's escaped to "%", and since there is no valid character after the "%" printf will be sweet enough just to display %. The solution is, as suggested, to replace all instances where you actually want to display "%" with "%%". |
| EVOEx is offline | |
| | #3 |
| Registered User Join Date: May 2009 Location: Chennai, India
Posts: 17
| EVOEx, Thanks for the clarification. -BalaC- |
| cbalu is offline | |
![]() |
| Tags |
| sprintf |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling sample DarkGDK Program | Phyxashun | Game Programming | 6 | 01-27-2009 03:07 AM |
| Including lib in a lib | bibiteinfo | C++ Programming | 0 | 02-07-2006 02:28 PM |
| Stupid compiler errors | ChrisEacrett | C++ Programming | 9 | 11-30-2003 05:44 PM |
| Linking error | DockyD | C++ Programming | 10 | 01-20-2003 05:27 AM |
| <list> | Unregistered | C++ Programming | 9 | 02-24-2002 04:07 PM |