Table of Contents
show
- Writes one character to a file.
- Function fputc receives as arguments a character to be written and a pointer for the file to which the character will be written.
- The function call fputc(‘a’, stdout) writes the character ‘a’ to stdout— the standard output.
- This call is equivalent to putchar(‘a’).
Syntax
fputc
int fputc(int char, FILE *pointer)
Program
#include<stdio.h>
int main()
{
int i = 0;
FILE *fp = fopen("output.txt","w");
// Return if could not open file
if (fp == NULL)
return 0;
char string[] = "Listen Class";
for (i = 0; string[i]!='\0'; i++)
{
// Input string into the file
// single character at a time
fputc(string[i], fp);
}
fclose(fp);
printf("Open the file output.txt");
return 0;
}
Output
Views: 0