printf - Prints out to stdin
fprintf - Prints out to a FILE *
sprintf - Prints out to a const char *
dprintf, snprintf, vprintf, vfprintf, vsprintf, vdprintf, vsnprintf
<< BACK
SYNOPSIS
Prototype - Simple
int printf(char *format, args*);Note that
args* means zero or more arguments. Think of
char * as a string.Prototype - Experienced
int printf(const char *restrict format, ...);
int fprintf(FILE *restrict format, ...);
int sprintf(char *restrict src, const char *restrict format, ...);
int dprintf(int fd, const char *restrict format, ...);
int snprintf(char str[restrict .size], size_t size, const char *restrict format, ...);
int vprintf(const char *restrict format, va_list ap);
...
Note that
... means zero or more arguments. EXAMPLES
printf
#include <stdio.h>
typedef const char* string;
int main(void)
{
string s = "cmanuals is cool!";
printf("%s", s); // Prints out "cmanuals is cool" to the screen
int i = 10;
printf("cmanuals is really %i/%i!", i); // Prints out "cmanuals is really 10/10!" to the screen
double d = 3.14159265358979;
printf("pi is %.14lf.", d); // Prints out "pi is 3.14159265358979" to the screen
}
fprintf
#include <stdio.h>
int main(void)
{
FILE *file = fopen("hellofile.txt", "w");
if (file == NULL)
{
return 1;
}
char *s = "Hello, file";
fprintf(file, "%s\n", s);
}
sprintf
#include <stdio.h>
int main(void)
{
char buf[32];
double pi = 3.14159265358979;
sprintf(buf, "%lf", pi);
}