This is a horrible C trick I use all the time for quick and dirty throwaway programs for reading in a string. It's definitely a bad way, and upon reaching EOF it behaves differently on different OSes, but still, it's handy sometimes.

{
	int x;
	char line[ 1000 ] ;

	/* this is horrible! but it's so easy. */
	x = fscanf(f, "%[^\n]%*c", line);
}

Log in or register to write something here or to contact authors.