Console Input/Output (I/O) in C is used for communication between a program and the user through the console, which is the text-based interface used by command-line programs.
Types of I/O:
There are two types of console I/O in C: formatted and unformatted.Formatted Console I/O Functions:
Formatted console I/O functions are used to read or write data in a specific format. The most commonly used formatted console I/O functions are printf() and scanf().
cprintf("The value of x is %d\n", x);
scanf("%d", &x);
sprintf( ) and sscanf( ) Functions:
The sprintf() function is used to format a string and store it in a buffer, while the sscanf() function is used to read formatted input from a string and store it in variables.cchar str[50];
int x = 10, y = 20;
sprintf(str, "The value of x is %d and y is %d", x, y);
sscanf(str, "The value of x is %d and y is %d", &x, &y);
Unformatted Console I/O Functions:
Unformatted console I/O functions are used to read or write data as raw bytes. The most commonly used unformatted console I/O functions are getchar() and putchar().cint ch;
ch = getchar();
putchar(ch);
No comments:
Post a Comment
Tell us how you like it.