Thread: doubts on scanf

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    14

    doubts on scanf

    My doubts ....

    1.
    Code:
     int main(void)
      
      {
    
        int i;
        scanf("%d", &i,&i);
        printf("%d",i);
       }
    Why doesn't the scanf stmt show any error?

    2.
    Code:
         int main(void)
    
        {
         int i;
         scanf("  ",&i);
         printf("%d",i);
         }
    This too doesn't show any errors.on the contrary the scanf stmt asks for input even though it does not retain the value keyed in. Why?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Because the compiler doesn't know any better as scanf() has to process the parameters you give it. Get it wrong, and its your fault, and the program will most likely crash and burn.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  2. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  3. scanf issue
    By fkheng in forum C Programming
    Replies: 6
    Last Post: 06-20-2003, 07:28 AM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM