fgets( ) in C
![]() |
| fgets( ) in C |
Through this article we will be going to discuss fgets( ) function of C in detail in which we will cover following topics.
- fgets( ) function in c
- header file for fgets( ) function in c
- return value of fgets( ) function in c
- fgets( ) function in c syntax
- fgets( ) function in c program
fgets( ) function in C
The fgets( ) function is nothing but, it is also a standard library function of C which is basically used to study characters from a stream(file) and these characters are stored within the string point to by way of str. It reads at maximum n-1 characters from the report where n is the second one argument. Fptr is a file pointer which factors to the report from which characters are study.
Header file for fgets( ) function in C
This file function is define in <stdio.h> which is stand for standard input-output header file.
Return value of fgets( ) function in C
fgets() function return ASCII code of the character read by the function and it also return the character present at the position of the file pointer
Syntax of fgets( ) function in C
int fgets(char *str , int n , FILE *pointer):
Example of fgets( ) function in C
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fptr;
char str[80];
fptr=fopen("test.txt","r");
while(fgets(str,8, fptr)!=NULL)
puts(str);
fclose(fptr);
return 0;
}
Conclusion
fgets( ) function basically used to read string value from a file that has been open in read mode.

