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.
#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.
- puts() displays a string of text without all printf()"s formatting magic.
- puts() always displays the newline character at the end of its output.
#include <stdio.h>
int main()
{
puts("error.");
return(0);
}
error.