Thread: Input doubt?

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1+23+456 = ?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 01:50 PM