The fputc() function writes the character (unsigned char) to the output stream, at the specified position (indicated by the associated file position indicator) and then advances the indicator appropriately. It takes two arguments integer and files stream. The integer value is internally converted to an unsigned char.
In the below code, I am writing A-Z in the newly created file (aticleworld.txt) using the fputc function.
#include <stdio.h>
int main()
{
int ch = 0;
FILE *fp = NULL;
//create a file
fp = fopen("aticleworld.txt", "w");
if(fp == NULL)
{
printf("Error in creating the file\n");
exit(1);
}
//Write A to Z in file
for(ch =65 ; ch <= 90 ; ++ch)
{
fputc(ch, fp);
}
//close the file
fclose(fp);
printf("A t0 Z written to the created file\n");
return 0;
}
In the below code, I am writing A-Z in the newly created file (aticleworld.txt) using the fputc function.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer