C Tutorial/stdio.h/puts

Материал из C\C++ эксперт
Версия от 13:32, 25 мая 2010; Admin (обсуждение | вклад) (1 версия: Импорт контента...)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

puts

Item Value Header file stdio.h Declaration int puts(const char *str); Function writes the string to the standard output device. The null terminator is translated to a newline. Return returns a nonnegative value on success or an EOF upon failure.


<source lang="cpp">#include <stdio.h>

 #include <string.h>
 int main(void)
 {
   char str[80];
   strcpy(str, "this is an example");
   puts(str);
   return 0;
 }</source>

puts() can print variables

puts() can display a string variable


<source lang="cpp">#include <stdio.h>

int main(){

   char *name= "asdf";

   puts(name);
   return(0);

}</source>

asdf

puts() function is a simplified version of the printf() function.

  1. puts() displays a string of text without all printf()"s formatting magic.
  2. puts() always displays the newline character at the end of its output.


<source lang="cpp">#include <stdio.h>

int main() {

   puts("error.");
   return(0);

}</source>

error.