putchar used to write one character to output device Example putchar (variable_name); #include<stdio.h> void main() { char alpha='x'; clrscr(); putchar(alpha); putchar('\n'); /*or*/ putchar('\Y'); getch(); }
The putchar function is an unformatted console output function that displays (in VDU) only one ascii character being passed to them. Examples being passed are:
1. putchar(65); // displays 'A' in monitor.
2. putchar('A'); // displays 'A' in monitor.
Note that only integer (decimal) can be passed in void _cdecl putchar(int _C); ranging from 0 to 255 (compliant to ASCII) or the character enclosed with ' '.
putchar ('\n');
Random example: while ((c= getchar()) != EOF) putchar (c);
input scanf() , getch() , getche() output printf() , putch() , putchar()
All three functions output a single character, either to the console or to a FILE. putc() takes a character argument, and outputs it to the specified FILE. fputc() does exactly the same thing, and differs from putc() in implementation only. Most people use fputc(). putchar() writes the character to the console, and is the same as calling putc(c, stdout). puts() is a multicharacter function and putchar() is single character function
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..
putchar ('\n');
putchar ('"'); puts ("""); etc
putchar ('%'); puts ("%"); printf ("%%"); etc...
1. use the help/manual 2. entirely different: put one character vs put string with formatted inserts
Random example: while ((c= getchar()) != EOF) putchar (c);
Printf is a function which can output a "string literal," which means that unlike its similiar, putchar, it can in fact print entire sentences, including formatted data. Also, it's defined in stdio.h.
input scanf() , getch() , getche() output printf() , putch() , putchar()
All three functions output a single character, either to the console or to a FILE. putc() takes a character argument, and outputs it to the specified FILE. fputc() does exactly the same thing, and differs from putc() in implementation only. Most people use fputc(). putchar() writes the character to the console, and is the same as calling putc(c, stdout). puts() is a multicharacter function and putchar() is single character function
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..
You would iterate over all characters within the string, printing each character with the putchar function. In C, strings are terminated with a null byte, so you'd stop when that null byte has been reached. Example: void printme(const char* me) { while (*me) { putchar(*me++); } } Needless to say this method is inefficient compared to using API that outputs the entire string at once, but the general approach of iterating over all characters in a string is used frequently.
write, putchar, putc, fputc etc
static void tobin_core (int n) { if (n>1) tobin_core (n/2); putchar ('0'+n%2); } void tobin (int n) { if (n<0) { putchar ('-'); n= -n; } tobin_core (n); }