Thread: Sprintf masks Doubt(s)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    14

    Yes i tried

    i have tried with this:

    Code:
        sprintf(msg, "Teste %02.2d",100);
        sprintf(msg, "Teste %02.2d",100000);
        sprintf(msg, "Teste %02.2d",100000000);
    
    
        sprintf(msg, "Teste %2.2d",100);
        sprintf(msg, "Teste %2.2d",100000);
        sprintf(msg, "Teste %2.2d",100000000);
    And still the same result for both.

    1 - And again, i dont want you to write a program for me, i just want to know whats the difference between 2 masks(o2.2 and 2.2).

    2 - I looked at the reference before and i understood that the 0 is used for left padding... Buf even if i dont use the 0 i still got the padding of 0 on the .2 number...

    i just want to know something like "ITS FOR PADDING" or "ITS FOR THIS OR THAT", dont a program write if you dont want to your "majesty" ^^

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by RLeePlusPlus View Post
    i have tried with this:

    Code:
        sprintf(msg, "Teste %02.2d",100);
        sprintf(msg, "Teste %02.2d",100000);
        sprintf(msg, "Teste %02.2d",100000000);
    
    
        sprintf(msg, "Teste %2.2d",100);
        sprintf(msg, "Teste %2.2d",100000);
        sprintf(msg, "Teste %2.2d",100000000);
    And still the same result for both.

    1 - And again, i dont want you to write a program for me, i just want to know whats the difference between 2 masks(o2.2 and 2.2).

    2 - I looked at the reference before and i understood that the 0 is used for left padding... Buf even if i dont use the 0 i still got the padding of 0 on the .2 number...

    i just want to know something like "ITS FOR PADDING" or "ITS FOR THIS OR THAT", dont a program write if you dont want to your "majesty" ^^
    Ummm... why don't you try changing all those 2s to 8s and see what happens?

    Really... rather than getting all ........ed off, do some real experimenting.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    14

    still got the same results

    i still got the same results, with or without the '0' preceding the width... Just for information, i'm using VS2010 express

    thank you

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by RLeePlusPlus View Post
    i still got the same results, with or without the '0' preceding the width... Just for information, i'm using VS2010 express

    thank you
    FFS go and read the link I posted, specifically the documentation about the width specifier!

    Once you do that, it will be clear that you will see a difference using a single digit value, like 7.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    14

    Why it doesn't matter in VS 2010?

    Why it doesn't matter in VS 2010? in GCC/GPP i have to put the 0?

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by RLeePlusPlus View Post
    Why it doesn't matter in VS 2010? in GCC/GPP i have to put the 0?
    Because that's the way the libraries are written.

    Really... I'm no more telepathic than you are... I have no idea why programmer A decides one thing and programmer B decides another.
    Just accept these things as they are, use them, and get on with it.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    14

    ok...

    man, you really S U CK S... telepatic? Its not about to accept and use! Its about WHY IS DIFFERENT or IS REALLY DIFERENT? What a stupid reply... leave this for who want to discuss. You should be banished for answer questions like this.

    and don't reply this, put your idead in you A SS

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by CommonTater View Post
    Because that's the way the libraries are written.

    Really... I'm no more telepathic than you are... I have no idea why programmer A decides one thing and programmer B decides another.
    Just accept these things as they are, use them, and get on with it.
    Can you stop feeding conslusions of his own poor experimentation back at him as though they were answers? It irks me almost as much it must irk him.
    He's stupidly listening to your interpretation of his results instead of actually reading the documentation, and is incorrectly concluding that Visual Studio is broken, which it is not.

    RLeePlusPlus they do give different results, you're just not reading the documentation to see what values would make it give different results. I've already told you one answer and yes it will give a different result in Visual Studio.
    Now stop wasting everyone's time and actually read the link posted. If you don't understand part of what it says then ask a specific question about that part.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-12-2010, 08:02 PM
  2. Doubt in using % symbol under sprintf
    By cbalu in forum Linux Programming
    Replies: 2
    Last Post: 09-11-2009, 04:37 AM
  3. LAN IP masks?
    By whackaxe in forum Networking/Device Communication
    Replies: 7
    Last Post: 07-12-2004, 04:30 AM
  4. Input Masks - PASSWORDS
    By destiny_believe in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2004, 02:03 PM
  5. Map masks?
    By Kavity in forum Game Programming
    Replies: 8
    Last Post: 11-11-2001, 03:00 AM