cscanf

From Appmethod Topics
Jump to: navigation, search

Go Up to conio.h Index

Header File

conio.h

Category

Console I/O Routines

Prototype

int cscanf(char *format[, address, ...]);

Description

Scans and formats input from the console.

cscanf scans a series of input fields one character at a time, reading directly from the console. Then each field is formatted according to a format specifier passed to cscanf in the format string pointed to by format. Finally, cscanf stores the formatted input at an address passed to it as an argument following format, and echoes the input directly to the screen. There must be the same number of format specifiers and addresses as there are input fields.

Note: For details on format specifiers, see scanf Format Specifiers.

cscanf might stop scanning a particular field before it reaches the normal end-of-field (whitespace) character, or it might terminate entirely for a number of reasons. See scanf for a discussion of possible causes.

Note: Do not use this function in Win32 GUI applications.

Return Value

cscanf returns the number of input fields successfully scanned, converted, and stored; the return value does not include scanned fields that were not stored. If no fields were stored, the return value is 0.

If cscanf attempts to read at end-of-file , the return value is EOF.

Example

#include <conio.h>
int main(void)
{
   char string[80];
   /* clear the screen */
   clrscr();
   /* Prompt the user for input */
   cprintf("Enter a string with no spaces:");
   /* read the input */
   cscanf("%s", string);
   /* display what was read */
   cprintf("\r\nThe string entered is: %s", string);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+