Revision as of 20:16, 20 June 2011 edit1exec1 (talk | contribs)Pending changes reviewers, Rollbackers50,085 edits added reference to the C standard + link to external C++ documentation site← Previous edit |
Latest revision as of 05:17, 26 April 2023 edit undoSteel1943 (talk | contribs)Autopatrolled, Extended confirmed users, Page movers, Pending changes reviewers, Rollbackers, Template editors197,741 edits Rcats |
(8 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
|
|
#REDIRECT ] |
|
{{lowercase|title=putchar}} |
|
|
|
|
|
|
|
{{Redirect category shell| |
|
'''putchar''' is a ] in the ] that writes a single ] to the ] stream, ].<ref>{{cite book |
|
|
|
{{R with history}} |
|
| url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf |
|
|
|
{{R to anchor}} |
|
| title=ISO/IEC 9899:1999 specification |
|
|
⚫ |
}} |
|
| at=p. 299, § 7.19.7.9 |
|
|
}}</ref> Its prototype is as follows: |
|
|
:<code>int putchar (int character)</code> |
|
|
|
|
|
The character to be printed is fed into the function as an argument, and if the writing is successful, the argument character is returned. Otherwise, ] is returned. |
|
|
|
|
|
The <code>putchar</code> function is specified in the ] ] ]. |
|
|
|
|
|
==Sample usage== |
|
|
The following program uses <code>]</code> to read characters into an array and print them out using the <code>putchar</code> function after an ] character is found. |
|
|
|
|
|
<source lang="c"> |
|
|
#include <stdio.h> |
|
|
|
|
|
int main(void) |
|
|
{ |
|
|
char str; |
|
|
int ch, i, n = 0; |
|
|
|
|
|
while ((ch = getchar()) != EOF && n < 1000) |
|
|
str = ch; |
|
|
|
|
|
for (i = 0; i < n; ++i) |
|
|
putchar(str); |
|
|
|
|
|
putchar('\n'); /* trailing '\n' needed in Standard C */ |
|
|
|
|
|
return 0; |
|
⚫ |
} |
|
|
</source> |
|
|
|
|
|
The program specifies the reading length's maximum value at 1000 characters. It will stop reading either after reading 1000 characters or after reading in an end-of-file indicator, whichever comes first. |
|
|
|
|
|
==See also== |
|
|
*] |
|
|
*] |
|
|
*] |
|
|
|
|
|
==References== |
|
|
|
|
|
{{reflist}} |
|
|
|
|
|
==External links== |
|
|
|
|
|
* |
|
|
|
|
|
] |
|
|
] |
|