why is this getting truncated

S

sankalp srivastava

#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
 
T

tonydee

#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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top