C - Input Format Constant Control String


You can include a sequence of one or more characters that isn't a format conversion specifier within the input format string.

By adding extra character in the format string you're indicating that you expect the same characters to appear in the input and scanf_s() should read them but not store them.

These have to be matched exactly, character for character, by the data in the input stream.

Any variation will terminate the input scanning process in scanf_s().


#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>

int main(void)
  int i = 0;//from  w ww .ja  v  a  2  s  . co  m
  int j = 0;
  int value_count = 0;
  float fp1 = 0.0f;
  printf("Enter: fp1 = 3.14159 i = 7 8\n");

  value_count = scanf_s("fp1 = %f i = %d %d", &fp1, &i, &j);
  printf("Count of values read = %d\n", value_count);
  printf("fp1 = %f\ti = %d\tj = %d\n", fp1, i, j);
  return 0;