C Tutorial/stdio.h/puts


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

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.


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

puts() can print variables

puts() can display a string variable


#include <stdio.h>
 
int main(){
    char *name= "asdf";
 
    puts(name);
    return(0);
}
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.


#include <stdio.h>
 
int main()
{
    puts("error.");
    return(0);
}
error.