Header Files:
Header files are those files which written at the top of the
program. It contains many pre-written functions. It is written
in the program starting with hash (#) symbol followed by
‘include' keyword and then the name of header file within angle
etc.
It is used for printing and taking as input.
Formatted Input Output
There are many types of input and output functions available in C language. Some of
them are mentioned below: -
float, integer, octal and hexadecimal values”) onto the output screen. We use printf() function with %d format specifier to display the value of an integer variable.
Format Code | Meaning |
%c | To read a single character |
%s | To read a string |
%d | To read a signed decimal integer (short) |
%ld | To read a signed long decimal integer |
%f | To read a float (short0 or a single precision value |
%lf | To read a double precision float value |
%e | To read a float value exponential |
%g | To read double float value |
%o | To read an octal integer only |
%x | To read a hexadecimal integer only |
%u | To read unsigned decimal integer (used in pointer) |
Format Code | Meaning |
%c | To read a single character |
%d | To read a signed decimal integer (short) |
%ld | To read a signed long decimal integer |
%e | To read a float value exponential |
%f | To read a float (short0 or a single precision value |
%lf | To read a double precision float value |
%g | To read double float value |
%h | To read short integer |
%i | To read an integer (decimal, octal, hexadecimal) |
%o | To read an octal integer only |
%x | To read a hexadecimal integer only |
%u | To read unsigned decimal integer (used in pointer) |
%s | To read a string |
%[..] | To read a string of words from the defined range |
%[^] | To read string of words which are not from the defined range |
Example to show the use of printf and scanf functions
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
printf(“Enter the value of i");
scanf(“%d”, i);
printf(“The vallue of I is:",i);
}
Unformatted I/O functions
Getchar() and Putchar() Functions
This function is an Input function. It is used for reading a single character from the keyborad. It is
buffered function. Buffered functions get the input from the keyboard and store it in the memory
buffer temporally until you press the Enter key.
The putchar function is an output function. It is used to display a single character on the screen.
Example: -
#include<stdio.h>
#include<conio.h>
void main()
{
int C;
printf(“Enter a character");
C=getchar();
putchar(C);
getch();
}
Gets() and Puts() Functions
gets() : Reads characters from the standard input and stores them as a string.
puts() : prints characters from the standard output. Just like printf statement.
Example: -
#include<stdio.h>
#include <conio.h>
int main()
{
char name[50];
printf("Enter your name: ");
gets(name);
printf("Your name is: ");
puts(name);
getch();
}
* getch()
This is also an input function. This is used to read a single character from the keyboard like getchar()
function. But getchar() function is a buffered is function, getchar() function is a non-buffered function.
The character data read by this function is directly assign to a variable rather it goes to the memory buffer,
the character data directly assign to a variable without the need to press the Enter key.
Difference between gets() and puts() functions
The main difference between gets and puts in C Language is that gets is a function that
reads a string from standard input while puts is a function that prints a string to the
standard output.
No comments:
Post a Comment
theengineerschoice01@gmail.com