Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements

Input/Output statements

Input/Output statements

  • Reading data from input device and displaying the result on the screen are the two main tasks of any programming in C
  • In ‘C’ language the input and output operations are carried out by using standard functions.
  • The programs for these functions are kept in the file.
  • The file must be included in the program to use these functions using the preprocessor directive as: #include

The i/o functions are classified into 2 types:

C supports two formatting functions: printf( ), scanf( )

  • printf( ) is used to convert data stored in the program into a text stream for output to monitor
  • scanf( ) is used to convert the text stream coming from the keyboard to data values and stores them in program variables
  • printf( ) function stands for print formatting
  • printf function takes data values, converts them to a text stream using formatting specifications in the control string and passes the resulting text stream to the standard output.

Rules

  • The name of printf function should be in lower case
  • The input (or arguments) to printf function are given within round or circular paranthesis
  • At least one input is required and the first input to printf function should always be a string literal
  • The inputs are separated by commasIf values of identifiers are to be printed with the help of print function, the first argument print function should be a format string (control string)
  • Format string consists of format specifiers.
  • A format specifier specifies the format according to which the format should be done

Syntax of control string

%[flags][width][.precision][length modifier] type specifier
  • Each control string must begin with %
  •  Flags is an optional argument which specifies output justification such as numerical sign, trailing zeros or octal, decimal or hexadecimal prefixes

Views: 0

Articles

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments