All pastes #479284 Raw Edit

Anonymous

public c v1 · immutable
·published 2007-05-09 17:28 UTC
rendered paste body
char *fgets(char *s, int n, FILE *stream){	size_t index = 0;	while (index < (n - 1))	{		int character = fgetc(stream);				// EOF or error and nothing read?		if (character == EOF && index == 0)return NULL;		// EOF or error?		else if (character == EOF)goto success;				s[index] = (char)character;		++index;				// newline?		if ((char)character == '\n')goto success;	}		success:		s[index] = '\0';		return s;}