Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:21:00+00:00 2026-05-25T12:21:00+00:00

Following is a simple program to print formatted 1.2 on HP & Linux. However,

  • 0

Following is a simple program to print formatted “1.2” on HP & Linux.
However, the behavior is different.
I do not want to make the question bigger but the program where this is actually occurring has a float value in a string, so using %f is not an option (even using sprintf).

Has anyone encountered this before? Which behavior is correct?

This should not be a compiler issue but still have tried it on gcc, icpc, icc, g++.

#include <stdio.h>

int main()
{
   printf("%s = [%010s]\n", "[%010s]",  "1.2");
   return 0;
}

**HP:**
cc test2.c -o t ; ./t
[%010s] = [00000001.2]

**Linux:**
icc test2.c -o t ; ./t
[%010s] = [       1.2]

Edit: Thank you all very much for the responses 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:21:01+00:00Added an answer on May 25, 2026 at 12:21 pm

    From the glibc printf(3) man page:

       0      The value should be zero padded.  For d, i, o, u, x, X, a, A, e,
              E,  f, F, g, and G conversions, the converted value is padded on
              the left with zeros rather than blanks.  If the 0  and  -  flags
              both  appear,  the  0  flag is ignored.  If a precision is given
              with a numeric conversion (d, i, o, u, x, and X), the 0 flag  is
              ignored.  For other conversions, the behavior is undefined.
    

    So a 0 flag with s cannot be expected to pad the string with 0s on glibc-based systems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
Hi I have question regarding cin and buffer. I want to make a simple
Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour(#FFFFFF) self.Bind(wx.EVT_PAINT,self.onPaint)
Based on the following simple program the bitwise left shift operator works only for
Consider the following simple C program that read a file into a buffer and
I need to write a simple program for work that does the following: read
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
In my simple OpenGL program I get the following error about exit redefinition: 1>c:\program
The following program is very simple: it outputs a single dot each half a
I write a simple program to print a image in JSF.... I have one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.