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(); }
putchar ('\n');
Random example: while ((c= getchar()) != EOF) putchar (c);
input scanf() , getch() , getche() output printf() , putch() , putchar()
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..
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
putchar ('\n');
putchar ('"'); puts ("""); etc
putchar ('%'); puts ("%"); printf ("%%"); etc...
Random example: while ((c= getchar()) != EOF) putchar (c);
1. use the help/manual 2. entirely different: put one character vs put string with formatted inserts
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()
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..
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
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); }