C/stdio.h/scanf — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 14:20, 25 мая 2010

scanf: read input

    
//Header file:     #include <stdio.h>  
//Declaration:     int scanf(const char *format, ...); 
// The scanf() Format Specifiers 
    
//Code Meaning
//%a:  Read a floating-point value (C99 only) 
//%A:  Same as %a (C99 only) 
//%c:  Read a single character 
//%d:  Read a decimal integer 
//%i:  Read an integer in either decimal, octal, or hexadecimal format 
//%e:  Read a floating-point number 
//%E:  Same as %e 
//%f:  Read a floating-point number 
//%F:  Same as %f (C99 only) 
//%g:  Read a floating-point number 
//%G:  Same as %g 
//%o:  Read an octal number 
//%s:  Read a string 
//%x:  Read a hexadecimal number 
//%X:  Same as %x 
//%p:  Read a pointer 
//%n:  Receive an integer value equal to the number of characters read so far 
//%u:  Read an unsigned decimal integer 
//%[ ]:  Scan for a set of characters 
//%%:  Read a percent sign 
  

  
  #include <stdio.h>
  int main(void)
  {
    char str[80], str2[80];
    int i;
    scanf("%79s", str); //scanf up to 79 chars into str
    return 0;
  }


scanf: skip the integer between the two strings

  
  #include <stdio.h>
  int main(void)
  {
    char str[80], str2[80];
    int i;
    printf("skip the integer between the two strings:");
    scanf("%s%*d%s", str, str2);
    return 0;
  }