why is this getting truncated

Discussion in 'C++' started by sankalp srivastava, Apr 20, 2010.

  1. #include<stdio.h>
    int main()
    {
    int i=8;
    printf("this is the %d%45456",i);
    return 0;
    }

    it truncates the %45677 part of the printf argument .
    I know this is a c specific question but i couln sort out any help
     
    sankalp srivastava, Apr 20, 2010
    #1
    1. Advertising

  2. sankalp srivastava

    tonydee Guest

    On Apr 20, 4:21 pm, sankalp srivastava <>
    wrote:
    > #include<stdio.h>
    > int main()
    > {
    >         int i=8;
    >         printf("this is the %d%45456",i);
    >         return 0;
    >
    > }
    >
    > it truncates the %45677 part of the printf argument .
    > I know this is a c specific question but i couln sort out any help


    If you want a literal percentage character, you need to escape it with
    another percentage character, i.e. use "...%d%%45456", i. As is, it's
    being mistaken for a width for a following conversion that's never
    completed - not a very safe thing to do. C++ streams are often easier
    and definitely safer (i.e. std::cout << "this is the " << i <<
    "%45456"). You probably want to print a '\n' character at the end
    too, as terminals often buffer and handle text on a per-line basis,
    and - at least under UNIX - some shells would write their next prompt
    over the output of the program above.

    Cheers,
    Tony
     
    tonydee, Apr 20, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,005
    Smokey Grindel
    Dec 2, 2006
  2. Bill

    Data getting truncated

    Bill, Jul 11, 2003, in forum: ASP General
    Replies:
    1
    Views:
    143
    Ray at
    Jul 11, 2003
  3. Nit Khair
    Replies:
    1
    Views:
    108
    Michael W. Ryder
    Oct 31, 2008
  4. Replies:
    3
    Views:
    121
    Jürgen Exner
    Oct 15, 2005
  5. Replies:
    7
    Views:
    274
    A. Sinan Unur
    Feb 14, 2006
Loading...

Share This Page