Skip to main content

Formatted input/output function in Turbo C Language

It is very easy to use unformatted input/output functions as discussed. We can read and display only characters not numbers using unformatted functions. Using formatted input/output functions, we can read integers, floating point number and characters. The formatted input function is scanf() and formatted output functions is printf().


int scanf(“format string”, &var1, &var2, &var3,……..&varn);

This function scanf() is used to read any type of data such as int, char, float, double and even string from the keyboard. It accepts the following two parameters:
format string consists of one or more format specifires starts with % symbol.
&var1, &var2, &var3, …., &varn represents the list of variables. Here, symbol ‘&’ refers to the address of the variable. In the memory locations identified by these addresses, the respective values are stored.

Formatted input/output function in Turbo C Language

Return Type int: The function returns an integer value. This integer value is the number of item that have been read successfully using the keyboard. But, we rarely use this return value in our programs.
The various format specifiers along with the associated meaning are shown in the following table:

Data Type
Format Specifier
Read a decimal integer value
Read an octal value
Read a hexadecimal value
Read a decimal, octal or hexadecimal value
Read an unsigned integer value
Read a short integer value
Read a floating point number
Read a floating point number
Read a floating point number
Read a character
Read a string (series of character)
Read a long floating point number or double
long int
Read a long integer value

The following table shows the way the user has to enter the values from the keyboard:

Input statement
Entering value
Input way
3 integer value
10 20 30
Where, a=10      b=20       c=30
3 integer value
Where, a=10      b=20       c=30
1 floating point value
Where, a=787.3.5
1 character value
Where, a=p
1 floating point value
1 integer value
1 character value
787.35 10 P
Where, a=787.35, b=10, c=P
3 integer values separated by ‘-‘ (hyphen) sign
Where, a=10, b=20, c=30
3 integer values separated by ‘/’ (slash) symbol
Where, a=10, b=20, c=30

Note: Do not use any escape sequences such as \t, \n etc. in scanf().

For example: Consider the following statement:
In the above statement, remove ‘\n’, otherwise it may give wrong output.
Now, let us see, some more ways of data reading using scanf() function are given below:
Input statement
Entering value
Input way
3 integer values
1 2 3
Where, a=1  b=2  c=3
11 22 33
Where, a=11  b=22  c=33
Where, a=10  b=20  c=30
102 030 4
Where, a=10  b=2  c=3
The remaining two digits 0 and 4 are ignored or can be read by a subsequent scanf()
1 string
Where, str=.Programming
Input the string till the end of line
Wlecome! To the dotprogramming
Where, str= Wlecome! To the dotprogramming
To read a string with space gets() function will used in place of scanf().
The “scanf(“%[^\n]s”,str);” function read and stored all the character untill user will not press enter key.

Formatted Output Function


Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video

Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:

      Suppose next node is allocated at an address 506, so the list becomes,

  Suppose next node is allocated with an address with an address 10,s the list become,

The other way to represent the linked list is as shown below:

 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …