Thread: scanf

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    scanf

    What does

    Code:
    int var;
    scanf("%*10d", &var);
    means?

    The * character and 10 number.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    Im not preety sure what do they mean with "Suppresses assignment. The conversion that follows occurs as usual, but no pointer is used; the result of the conversion is simply discarded.".

    I mean what should i do in the following code below; when suppression is turned on? Should i just getchar() the next input field?

    If the next input field is a valid one for the called scanf, just ignore it if suppression is turned on?

    Code:
    int minscanf(char *fmt, ...)
    {
        va_list ap;
        char *p;
        int suppression;
        int field;
        
        union {
              int ival;
              short int sival;
        } val;
        
        va_start(ap, fmt);
        for(p = fmt; *p; p++) {
              while(*p == ' ' || *p == '\t')
                 p++;
              
              if(*p == '\0')
                 break;
                 
              suppression = field = 0;
              if(*p == '%') {
                    if(*++p == '\0')
                        break;
                    if(*p == '*') {
                       suppression = 1;
                       if(*++p == '\0')
                          break;
                    }
                    while(isdigit(*p) && *p) 
                       field = field * 10 + *p++ - '0';
              }
              if(suppression) {
                   
              }
        }
    }
    Last edited by Tool; 02-18-2010 at 01:48 PM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MSDN
    An asterisk (*) following the percent sign suppresses assignment of the next input field, which is interpreted as a field of the specified type. The field is scanned but not stored.
    I interpret this as scanf actually reads the data in the field specifier but doesn't store the data in any variable.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    36

    scanf:

    I want to add one more thing to the Elysia's answer.

    As he mentioned,* operator in the format specifier of scanf function is used to suppress the assignment of the input to a pointer.scanf won't include it in the count of successful assignments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  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