Node:getdelim, Previous:getline, Up:String input


The getdelim function is a more general form of the getline function; whereas getline stops reading input at the first newline character it encounters, the getdelim function enables you to specify other delimiter characters than newline. In fact, getline simply calls getdelim and specifies that the delimiter character is a newline.

The syntax for getdelim is nearly the same as that of getline, except that the third parameter specifies the delimiter character, and the fourth parameter is the stream from which to read. You can exactly duplicate the getline example in the last section with getdelim, by replacing the line

bytes_read = getline (&my_string, &nbytes, stdin);

with the line

bytes_read = getdelim (&my_string, &nbytes, '\n', stdin);