C fgets() – Read Line : from File




Fgets : Read Line of Character from File


Syntax :

#include<stdio.h>
char * fgets(char* str,int n,FILE *stream);

str  –  String to be Written on Stream
*Stream – File Pointer
n : Maximum number of Characters to be read


What it does ?

  1. fgets reads line of Character from Stream
  2. fgets reads characters from stream into the string s. It stops when it reads either n – 1 characters or a newline character, whichever comes first.
  3. On success, fgets returns the string pointed to by str.
  4. On end-of-file or error fgets returns null.

Live Example :

#include<stdio.h>

int main(void)
{
char msg[80];
fgets(msg, strlen(string)+1, stream);
}

Header File   :  stdio.h


Bookmark & Share