Previous | Home | Next |
fputc() Function: This function writes a character to a specified file at the current file position and then increment the file position pointer. The putc() macro acts essentially identically to fputc(), but is a macro that expands in-line. It may evaluate stream more than once, so arguments given to putc() should not be expressions with potential side effects.
The fputc() function returns an integer representing the character written. If a write error occurs the error indicator is set and fputc() returns EOF.
#include<stdio.h>
void main()
{
FILE *p;
char ch;
if((p==fopen("myfile.txt","w"))== NULL)
{
printf("this file does not
exist\n");
exit()
}
else
{
while((ch==getchar())!=EOF)
fputc(ch,p);
}
fclose(p);
};
Previous | Home | Next |