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:
![](data:image/webp;base64,UklGRm4cAABXRUJQVlA4IGIcAABQcgCdASq2AYsAPok+mkmlIyKhJLbscKARCWlu/GMvIqKUGeO8Lo9urb/7ahuju9yUwh9e/HDz78XHnb2n9XzNn1Nf2PoV/HvtV+b/sv+I/6/+C+jP7d/qPA/4Cf3PqBfmH8z/z/9r/Hz0zf7P/B923s/+n/y3qBevXzr/Kf3L97/7N8Tvqn+Z/un7lf1r4D/Of7V7AH8r/of+u/OX+4fKX+P8D76d/sv2A/ID7Af5J/Tf9z/e/3L/u3/////1uf73+U/1n7be3r9B/vv/c/yv+p+Qj+X/1D/ff3b/LftT86/s+9KX90DA/27SGm2zxSe0Z8WZ38OHJHxTIanq7nrrKFSXa3NMMdelwu5waKTLy1YLlpXpQU3Gh23DVOw9HGJSurCLDPLoWHQTcbln0teil2c2chVLMgCnAG1E/AnLrAMDfmyJNd6OV9pNnr+3onhO+57tRXF2uubxPejNAC04fRsSrlOF2TBWHVPtad692wt1+kPCk+wWDwqxwV+ryReoXErJYw8l/AmIsKGS/SmQtLwzUu09xo6O+2bNesTSSfu4guHo0FRXEJv9+QLKLOWdA1dCCDyVu/25BI292q2C7fwmQSeLTtKznTvNvV97Bf86gE/n2d73aJ5YBNY34MalfhRuMbkU6JwLan5jh/9wz0YmYt6FQL0MR0VP9BiyEb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o1WmAAiEUCWeRs5lmIy0TaX84kzBvckSXnBR/v/EDSQYIdzEfI/btnoYQLvwlpLS7YLtK2MC+j5ZK1TzeOzjoho8GpMLjs1eUsGyl6yTYYgR9B6HiWbvZkW9le8jLZqwAzthzUPyVx2tnyJ9Vivg6UXI504fTNX9Zw7HVKf1Dg9EzOdD7V8mOcy6wTxcHib8Pdl4Gx9uJ0AuejEGRPy6N4lsvw25/2apvx1Dk/OJsCQjjts7ajCcbGOj0HlvxQIHK+0Bkqyy+PUajjen46LNbqX/Y1fXE8039L8SjKAfbKajIs8yTAeuECj4jc0HBbJFh5LiHFSGwJOUJO/6cW0fxy6D/n/IRxNzWmg7zDoGVO9RbsAJq0LQAAAAAAAAA=)
need an explanation for this answer? contact us directly to get an explanation for this answer