Friday 2 June 2023

Input and Output in C

What is Input – Output in C?

There are three main task of any program – it takes data as input, procedure this data and gives the output. The input operation require motion of data from an (generally keyboard) input device to computer memory, while in output function the data moves from computer reminder to the (generally screen) output device. The input output is executed through a set of library operation that is give with every C compiler.

C compiler, computer memory, header files
Input and Output in C language image-1

There are some header files that supply mandatory details in support of the many library functions. These header files are set foot in the program using the #include instruction at the starting point of the program. For example if a project uses any function from, the quality I/O library, then it should involve the header file stdio.h as-

#include <stdio.h>

Likewise there are other header files like stdlib.h, string.h that should be added when certain library functions are used.

An easy method for taking the data as input is to give the usefulness to the variables by task statement. For example-

int basic = 2000;

Char ch=’y’;

But in this way we can give only specific data to the variables. The second procedure is to use the input function scanf(), which takes the input facts from the keyboard. In this procedure we can give any value to the change at run time.

Conversion specifications

The functions scanf() and printf() make use of change stating to identify the type and size of data. Each transformation specification must begin with a percent sign(%). Some altering specifications are as given below-

%d – a decimal integer, %x – a hexadecimal integer, %f – a floating point number, %c – a single character, %o – an octal integer, %s – a string and %u – an unsigned decimal integer

Reading input data

Input data can be beginning into the memory from a worth input device (key board). C provides the scanf() library purpose for beginning input data. This task can take all types of utility as input. The scanf() function can be written as – scanf(“control string”, address1, address2,so on);

This task should have at least two variables. A first variable is a authority string, which carry conversion specification characters. It should be within double restate. The conversion specification nature may be one or more; it be able to trust on the number of change we want to input. The other variable are mark of variables. In the scanf() function at least one mark should be present. The mark of a variable is found by prior the changing name by an ampersand (&) sign. A string variable is not lead up to by & signs to get the mark.


Computer stuff kit tricks of Topics 47.