Revision as of 00:28, 19 July 2006 edit193.1.172.138 (talk) →Sample usage← 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 |
(19 intermediate revisions by 12 users not shown) |
Line 1: |
Line 1: |
|
|
#REDIRECT ] |
|
{{lowercase|title=putchar}} |
|
|
|
|
|
|
|
{{Redirect category shell| |
|
'''putchar''' is a ] in ] that writes a single ] to the ] stream, ]. Its prototype is as follows: |
|
|
|
{{R with history}} |
|
:<code>int putchar (int character)</code> |
|
|
|
{{R to anchor}} |
|
|
|
|
⚫ |
}} |
|
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 ] to read characters into an array and print them out using the <code>putchar</code> function after an ] character is found. |
|
|
|
|
|
<pre> |
|
|
#include <stdio.h> |
|
|
|
|
|
int main(void) |
|
|
{ |
|
|
char str; |
|
|
int ch, n = 0; |
|
|
|
|
|
while ((str = getchar()) != EOF && n < 1000) |
|
|
++n; |
|
|
|
|
|
for (int i = 0; i < n; ++i) |
|
|
putchar(str); |
|
|
|
|
|
putchar('\n'); /* trailing '\n' needed in Standard C */ |
|
|
|
|
|
return 0; |
|
⚫ |
} |
|
|
</pre> |
|
|
rertrtret |
|
|
tetr |
|
|
er |
|
|
tret |
|
|
ret |
|
|
ret |
|
|
e |
|
|
t |
|
|
e |
|
|
t |
|
|
et |
|
|
|
|
|
t |
|
|
|
|
|
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 indicatorm, whichever comes first. |
|
|
|
|
|
==See also== |
|
|
*] |
|
|
*] |
|
|
*] |
|
|
|
|
|
==References== |
|
|
* |
|
|
|
|
|
] |
|