What is the Difference Between printf and fprintf?
🆚 Go to Comparative Table 🆚The main difference between printf
and fprintf
lies in the destination of their output. Here's a summary of their differences:
- printf: This function is used to print character data on the standard output stream (stdout), which is typically the console or monitor. The syntax for
printf
is:printf(const char* format, ...);
. - fprintf: This function is used to print character data on a named output stream, such as a file. The syntax for
fprintf
is:fprintf(FILE *stream, const char *format, ...);
. TheFILE *stream
parameter is a file pointer that indicates the file where the formatted data will be saved.
In summary, printf
is used to display output on the console, while fprintf
is used to write output to a specified file or output stream.
Comparative Table: printf vs fprintf
The main difference between printf
and fprintf
is that printf
is used to print a formatted string to the standard output stream (stdout
), while fprintf
is used to print a formatted string to a file. Here is a table summarizing their differences:
Function | Output Destination | Syntax | Description |
---|---|---|---|
printf |
Standard output stream (stdout ) |
printf(const char* format, ...) |
Prints formatted string to the console |
fprintf |
File | fprintf(FILE *fptr, const char *format, ...) |
Prints formatted string to a file specified by the file pointer fptr |
Typically, printf
is used when you want to produce output to the console for a user, while fprintf
is used to produce output to a file.
Read more:
- scanf vs gets
- Echo vs Print
- getc vs getchar
- Printer vs Plotter
- C vs C++
- Quick Format vs Format
- StringBuffer vs StringBuilder
- Matlab vs C Language
- Python vs C Language
- C vs Objective C
- calloc vs malloc
- Function Prototype vs Function Definition in C
- System Call vs Function Call
- C vs Embedded C
- Unicode vs ASCII
- Java vs C language
- Procedures vs Functions in Programming
- PDF vs DOC
- DOC vs RTF