Putchar

Putchar

putchar is a function in C programming language that writes a single character to the standard output stream, stdout. Its prototype is as follows::int putchar (int character)

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, end-of-file is returned.

The putchar function is specified in the C standard library header file stdio.h.

ample usage

The following program uses getchar to read characters into an array and print them out using the putchar function after an end-of-file character is found.

#include

int main(void) { char str [1000] ; int ch, n = 0; while ((ch = getchar()) != EOF && n < 1000) str [n++] = ch; for (int i = 0; i < n; ++i) putchar(str [i] );

putchar(' '); /* trailing ' ' needed in Standard C */ return 0; }

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.

ee also

*stdio.h
*C standard library
*getchar

References

* [http://www.cplusplus.com/ref/cstdio/putchar.html putchar on Cplusplus.com]


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Automata-based programming — is a programming paradigm in which the program or its part is thought of as a model of a finite state machine or any other (often more complicated) formal automata (see automata theory). Sometimes a potentially infinite set of possible states is… …   Wikipedia

  • Автоматное программирование — Автоматное программирование  это парадигма программирования, при использовании которой программа или её фрагмент осмысливается как модель какого либо формального автомата. В зависимости от конкретной задачи в автоматном программировании… …   Википедия

  • Hello world program — Hello World redirects here. For the 2009 compilation album by Michael Jackson, see Hello World: The Motown Solo Collection. For the song by Lady Antebellum, see Hello World (song). A GUI Hello World program, written in Perl …   Wikipedia

  • Hello world — Pour les articles homonymes, voir Hello (homonymie). Un programme Hello World d interface graphique, écrit en langage Perl …   Wikipédia en Français

  • Assembleur — Cet article concerne le langage d assemblage. Pour le programme produisant un exécutable à partir d un source écrit dans ce langage, voir Programme assembleur. Un langage d assemblage ou langage assembleur ou simplement assembleur par abus de… …   Wikipédia en Français

  • Assembleur (langage) — Assembleur  Cet article concerne le langage d assemblage. Pour le programme produisant un exécutable à partir d un source écrit dans ce langage, voir Programme assembleur. Un langage d assemblage ou langage assembleur ou simplement… …   Wikipédia en Français

  • Indent — Développeur Projet GNU Dernière version …   Wikipédia en Français

  • Langage Assembleur — Assembleur  Cet article concerne le langage d assemblage. Pour le programme produisant un exécutable à partir d un source écrit dans ce langage, voir Programme assembleur. Un langage d assemblage ou langage assembleur ou simplement… …   Wikipédia en Français

  • Langage assembleur — Assembleur  Cet article concerne le langage d assemblage. Pour le programme produisant un exécutable à partir d un source écrit dans ce langage, voir Programme assembleur. Un langage d assemblage ou langage assembleur ou simplement… …   Wikipédia en Français

  • Langage d'assemblage — Assembleur  Cet article concerne le langage d assemblage. Pour le programme produisant un exécutable à partir d un source écrit dans ce langage, voir Programme assembleur. Un langage d assemblage ou langage assembleur ou simplement… …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”