C Tutorial/stdio.h/puts
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.
- puts() displays a string of text without all printf()"s formatting magic.
- 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.