Scroll Down to See All▾
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1ynFunction Details : getc
intgetc(FILE * stream) ;
Return Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
Read about return values of getc function .
1st Parameter Type : FILE *
Pointer to FILE structure for file operations
1st Parameter
Pointer to the file stream from which a character is to be read
Read more about parameters of getc in parameters section
The getcfunction in C language reads the next character from the specified stream.
The getc function obtains the next character (if present) as an unsigned char converted to an int, from the input stream pointed to by argument, and advances the associated file position indicator for the stream (if defined). getc is pretty similar to fgetc except the fact that it may be implemented as a macro.
Repeated calls to getc read consecutive characters from the stream until EOF or an error occurs.
getc function can be used with any input stream, not just files. This includes standard input (stdin) and other streams like those associated with pipes, sockets, or other I/O sources, as long as they are represented by a FILE* pointer.
This function is often used with loops in C, especially when you need to read multiple characters from a stream (like a file or standard input) until the end of the stream is reached. This is because getc reads only one character at a time, so a loop is necessary to process an entire stream.
Repeated calls to getc read consecutive characters from the stream until EOF or an error occurs.
getc function can be used with any input stream, not just files. This includes standard input (stdin) and other streams like those associated with pipes, sockets, or other I/O sources, as long as they are represented by a FILE* pointer.
This function is often used with loops in C, especially when you need to read multiple characters from a stream (like a file or standard input) until the end of the stream is reached. This is because getc reads only one character at a time, so a loop is necessary to process an entire stream.
To Summarize the Workflow:
- 1.Function receives a pointer to a FILE stream (getc(FILE *stream))
- 2.Attempts to read the next character from the provided stream
- 3.On success: Reads character, converts to unsigned char, returns as integer (0-255)
- 4.On EOF (end of file): Returns EOF (-1) and sets EOF indicator for stream
- 5.On read error: Returns EOF (-1) and sets error indicator for stream
- 6.Stream position advances one character on success, remains unchanged on failure
Read more about return type and value ofgetc function in return section.
The getcfunction takes 1
parameter:
- •FILE * `stream`: Pointer to the file stream from which a character is to be read
The getc function return value :
Output
This example demonstrates basic usage of getc to read characters from a file and print them to the console. It also shows how to check for errors and end-of-file conditions.