Input-Output function means the function used to take input is called input function like scanf(). The function used to display output is...

Input-Output functions

/
0 Comments

  • Input-Output function means the function used to take input is called input function like scanf(). The function used to display output is a called output function.
  • Input function is scanf( ). it required two parameters first is for which type of data will take line int, char etc.
  • Output function is printf () is used to display output on the screen. mostly it takes one parameter and if you want to display any variable value it contains more then one parameter.
  • Scanf() and Print( ) both funtion are in stdio.h libaray.

Printf( )

  • The output function printf translates internal values to characters. We have used printf informally in previous chapters. The description here covers most typical uses but is not complete.
  •  printf(char *format, arg1, arg2, ...);
  • printf converts, formats, and prints its arguments on the standard output under control of the format. It returns the number of characters printed. 

  • Theory:

  • The format string contains two types of objects: ordinary characters, which are copied to the output stream, and conversion specifications, each of which causes conversion and printing of the next successive argument to printf. Each conversion specification begins with a % and ends with a conversion character. 
  • - A minus sign, which specifies left adjustment of the converted argument
  • A number that specifies the minimum field width. The converted argument will be printed in a field at least this wide. If necessary it will be padded on the left (or right, if left adjustment is called for) to make up the field width.
  •  A number, the precision, that specifies the maximum number of characters to be printed from a string, or the number of digits after the decimal point of a floating-point value, or the minimum number of digits for an integer.
  • A warning: printf uses its first argument to decide how many arguments follow and what their type is. It will get confused, and you will get wrong answers if there are not enough arguments of if they are the wrong type. You should also be aware of the difference between these two calls:
  • printf(s); /* FAILS ifs contains % */ p
           printf("%s", s); /* SAFE */

Scanf( )

  • The function scanf is the input analog of printf, providing many of the same conversion facilities in the opposite direction. 
  • scanf(char *format, ...);
  • scanf reads characters from the standard input, interprets them according to the specification in format, and stores the results through the remaining arguments. The format argument is described below; the other arguments, each of which must be a pointer, indicate where the corresponding converted input should be stored. As with printf, this section is a summary of the most useful features, not an exhaustive list. 
  • Theory:
  • scanf stops when it exhausts its format string, or when some input fails to match the control specification. It returns as its value the number of successfully matched and assigned input items. This can be used to decide how many items were found. On the end of the file, EOF is returned; note that this is different from 0, which means that the next input character does not match the first specification in the format string. The next call to scanf resumes searching immediately after the last character already converted.
  • scanf(char *string, char *format, arg1, arg2, ...) 
  • It scans the string according to the format in format and stores the resulting values through arg1, arg2, etc. These arguments must be pointers.
  • The format string usually contains conversion specifications, which are used to control conversion of input.  
  • The conversion characters d, i, o, u, and x may be preceded by h to indicate that a pointer to short rather than int appears in the argument list, or by l (letter ell) to indicate that a pointer to long appears in the argument list
#include<stdio.h> is used to for scanf() and printf() function
#include<conio.h> is used to console input output.
%d is for integer
%c is for character
%s is for string
%f is for float
%lf is for Double
& is used as to address mean it is used to store the value in a variable.for example
int a;
scanf("%d",&a);
%d is for to take inter type value And & is used to store that value in a.if we want to display that value then we no need & but we need %d
printf("%d",a);
getch(); is used to hold output on screen if we, not screen will open and close in seconds.

Program:


#include<stdio.h>

#include<conio.h>

void main()

{clrscr();          /* cleaning screen*/

int a;               /*declaring integer typevariable a */

char f;          /*declaring character type variable f */

printf("enter name");      /* print*/

scanf("%c",&f);             /* taking character type value and storing inf */

printf("enter number");   /*again printing*/

scanf("%d",&a);        /* taking integer type value and storing in a*/

printf("name=%c number=%d",f,a);    /*displaying value of variable f and a */

getch();                               /*holding output on screen*/

}


 Output:


ForAny Kind of query, doubt And Error live message in cybersquad App . You will get full-time support.I will reply back within an hour.

No comments:

Cybercry 2018. Powered by Blogger.

Popular Posts