Input doubt?

This is a discussion on Input doubt? within the C Programming forums, part of the General Programming Boards category; Dear All, i have doubt in working of scanf:- Code: void main() { int a,b,c; scanf("%1d %2d %3d",&a,&b,&c); printf("Sum=%d",a+b+c); } ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    Input doubt?

    Dear All,
    i have doubt in working of scanf:-

    Code:
    void main()
          	{
    	  int a,b,c;
    	  scanf("%1d %2d %3d",&a,&b,&c);
    	  printf("Sum=%d",a+b+c);
          	}
    if i give input as 123456 44 544
    output is = 480
    How it is possible?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,459
    1+23+456 = ?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    find out whats happening by printing out the values of a,b,c respectively

    Code:
    scanf("%d %d %d",&a,&b,&c);
    fflush(stdin);
    not %1d %2d %3d

    learn about padding...
    Last edited by creeping death; 03-20-2009 at 01:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. continues input
    By Matty_Alan in forum C Programming
    Replies: 2
    Last Post: 06-22-2007, 10:04 PM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 01:50 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21