Programmer's Wiki
Advertisement

This function is specific to Microsoft compilers. It is the same as scanf, except it does not cause buffer overload.  It takes the input in a text based console program and places it into a variable.

Syntax

int scanf_s(
  const char *format [,
  argument]...
);


Format - The format of the incoming string

Argument - Optional variables to place the incoming data

Usage

This function will be used when input is required in console programs.  This will receive all input on the line until the enter key is pressed.  It will then place the value into the variables you have declared.  This is the same as scanf, except it is safe.  This is an example:

#include<stdio.h>

int main()
{
   char c;
   printf("Enter a letter");
   scanf_s("%c", &c, 14);
   printf("%s",&c);
   return 0;
}

C Programming For Beginners

Advertisement