Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

Learn C Language

fgetc() Function in C Programming Language

fgetc() Function in C
Get character from stream. Returns the character currently pointed by the internal file position indicator of the specified stream. The internal file position indicator is then advanced to the next character. If the stream is at the end-of-file when called, the function returns EOF and sets the end-of-file indicator for the stream (feof). If a read error occurs, the function returns EOF and sets the error indicator for the stream (ferror). fgetc and getc are equivalent, except that getc may be implemented as a macro in some libraries.
Syntax for fgetc() Function in C
#include <stdio.h> int fgetc ( FILE * stream );
stream
Pointer to a FILE object that identifies an input stream. fgetc() is used to obtain input from a file single character at a time. This function returns the ASCII code of the character read by the function. It returns the character present at position indicated by file pointer. After reading the character, the file pointer is advanced to next character. If pointer is at end of file or if an error occurs EOF file is returned by this function. On success, the character read is returned (promoted to an int value). The return type is int to accommodate for the special value EOF, which indicates failure: If the position indicator was at the end-of-file, the function returns EOF and sets the eof indicator (feof) of stream. If some other reading error happens, the function also returns EOF, but sets its error indicator (ferror) instead.
/* get character from stream by fgetc() function example */ /* Open, Read and close a file: Reading char by char */ # include <stdio.h> int main( ) { FILE *fp ; char c ; printf( "Opening the file test.c in read mode" ) ; fp = fopen ( "test.c", "r" ) ; // opening an existing file if ( fp == NULL ) { printf ( "Could not open file test.c" ) ; return 1; } printf( "Reading the file test.c" ) ; while ( 1 ) { c = fgetc ( fp ) ; // reading the file if ( c == EOF ) break ; printf ( "%c", c ) ; } printf("Closing the file test.c") ; fclose ( fp ) ; // Closing the file return 0; }

C Program example Return the largest of the two passed numbers. Return smallest of the two passed numbers. Load some random values into the array. Print set of numbers.


C program input decimal number and convert to Hexadecimal number system. The Decimal number system is a base 10 number system. Decimal number system uses 10 symbols to...

C Program to Arrange numbers in Ascending order. Code 'prompts user' for the n numbers, once the user is done entering those numbers and this c program sorts and displays them in



Program find number of words, blank spaces, Special symbols, Digits, "Vowels" by pointers. We are going to accept string use 'gets()'. We are not using scanf() to accept string because



Program stores a sentence entered by user in a file. After termination of this program, you can see a text file program.txt created in the same location where this program is located.


For loop to print value and address of each element of array. Just to demonstrate that the array elements are stored in contiguous locations, I am displaying the addresses in...