This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf

Hi,

I am trying to run my first C program on Keil...it works perfectly until I insert a printf statement...am i missing something?

#include <reg52.h>
#include <stdio.h>

void main(void)
{
        unsigned int i;

        unsigned int ans = 0;

        for (i =0; i< 5; i++)
        {
                ans += 2;
        }

        printf("The answer is: " + ans);
}

Parents
  • oo im sry...was too tired to notice i pasted the wrong code!

    this should have been it:

                               #include <reg52.h>
    #include <stdio.h>
    
    void main(void)
    {
            unsigned int i;
    
            unsigned int ans = 0;
    
            for (i =0; i< 5; i++)
            {
                    ans += 2;
            }
    
            printf("The answer is: %u",ans);
    
            ans += 2;
    }
    

    i cant really think of what is going wrong...:S my actual point of doing this program is in using the printf...but it wasnt working...so i thought of adding some maths...and it actually was stepping them well...but as soon as it reaches printf, it blocks :s

Reply
  • oo im sry...was too tired to notice i pasted the wrong code!

    this should have been it:

                               #include <reg52.h>
    #include <stdio.h>
    
    void main(void)
    {
            unsigned int i;
    
            unsigned int ans = 0;
    
            for (i =0; i< 5; i++)
            {
                    ans += 2;
            }
    
            printf("The answer is: %u",ans);
    
            ans += 2;
    }
    

    i cant really think of what is going wrong...:S my actual point of doing this program is in using the printf...but it wasnt working...so i thought of adding some maths...and it actually was stepping them well...but as soon as it reaches printf, it blocks :s

Children