Help us and donate little Bitcoins to pay the server costs: 1AXLPuRUBYc1JczTW4XS65GL6oWjNP2Vt2

User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)


    char *fgets(char *str, int n, FILE *stream);

Copies characters from (input) stream stream to sstr, stopping when n-1 characters copied, newline copied, end-of-file reached or error occurs. If no error, str is NUL-terminated. Returns NULL on end-of-file or error, str otherwise.

C Sourcecode Example

 * fgets example code
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#define MAX 20 
int main( void )
  FILE *stream;
  char string[MAX];
  if((stream=fopen("test.txt","r"))==NULL) {
    printf("Cannot open file.\n");
    return 1;
  fgets(string, MAX, stream);
  printf("%s\n", string);
  return 0;


content of test.txt

test 123456789,123456789
 ... # ...
this is a test for 

fgets output example

  test 123456789,1234
c/stdio.h/fgets.txt · Last modified: 2013/01/22 22:02 (external edit)

The new Question & Answer System is online and waiting for your Questions about Programming problems Impressum