Scroll Down to See All▾
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1ynFunction Details : fputc
intfputc(int ch,FILE * stream) ;
Return Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
Read about return values of fputc function .
1st Parameter Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
1st Parameter
The character to write, represented as an 'unsigned char' cast to an 'int'.
Despite being int:
Value is converted to unsigned char (0-255);
Values outside this range still work (only last byte used);
EOF as input causes undefined behavior;
Despite being int:
Value is converted to unsigned char (0-255);
Values outside this range still work (only last byte used);
EOF as input causes undefined behavior;
2nd Parameter Type : FILE *
Pointer to FILE structure for file operations
2nd Parameter
Pointer to the file stream where the character will be written
Must be open for writing ("w", "a", "r+", etc.);
Must be valid (not NULL);
Must not be closed;
Position advances by one on success;
Must be open for writing ("w", "a", "r+", etc.);
Must be valid (not NULL);
Must not be closed;
Position advances by one on success;
Read more about parameters of fputc in parameters section
The fputcfunction in C language writes a single character to a specified stream, converting it to unsigned char during the process.
fputc is a fundamental character output function used for writing single characters to a stream, commonly used in character-by-character file writing or output formatting. What makes it special is its handling of the input parameter as an int (not char), converting it to unsigned char before writing, which allows it to handle the full range of byte values (0-255) safely. It is typically used alongside fgetc for character-by-character I/O operations, ferror for error checking, and relies on fopen for stream initialization with write permissions ("w", "a", "r+", etc.).
To Summarize the Workflow:
- 1.Takes int character value and FILE pointer as parameters
- 2.Converts character to unsigned char before writing
- 3.Writes single character to specified stream
- 4.Returns character written on success
- 5.Returns EOF and sets error indicator on failure
- 6.Advances stream position by one character on success
Read more about return type and value offputc function in return section.
The fputcfunction takes 2
parameters:Edge cases:
● NULL stream: undefined behavior
● Already closed stream: undefined behavior
● Stream in read-only mode: returns EOF, sets error indicator
● Buffer full: triggers automatic flush before write
- •int `ch`: The character to write, represented as an 'unsigned char' cast to an 'int'.
Despite being int:
Value is converted to unsigned char (0-255);
Values outside this range still work (only last byte used);
EOF as input causes undefined behavior;
- •FILE * `stream`: Pointer to the file stream where the character will be written
Must be open for writing ("w", "a", "r+", etc.);
Must be valid (not NULL);
Must not be closed;
Position advances by one on success;
● NULL stream: undefined behavior
● Already closed stream: undefined behavior
● Stream in read-only mode: returns EOF, sets error indicator
● Buffer full: triggers automatic flush before write
The fputc function return value :
- On success: returns the character written (as unsigned char converted to int)
- On failure: returns EOF (-1) and sets error indicator
- Same character value is returned that was actually written
- Return value can be safely compared with EOF
- Must cast to unsigned char to get actual written value
Output
This example demonstrates the basic usage of `fputc`. It writes each character of a string to a file individually.