MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


String Pattern-Matching Library Functions             bgets(3GEN)



NAME
     bgets - read stream up to next delimiter

SYNOPSIS
     cc [ flag ... ] file ... -lgen [ library ... ]
     #include 

     char *bgets(char *buffer, sizet count, FILE  *stream,
          const char *breakstring);


DESCRIPTION
     The bgets()  function  reads  characters  from  stream  into
     buffer until either count is exhausted or one of the charac-
     ters in breakstring is encountered in the stream.  The  read
     data  is terminated with a null byte ('\0') and a pointer to
     the trailing null is returned. If a breakstring character is
     encountered,  the  last  non-null is the delimiter character
     that  terminated the scan.


     Note that, except for  the  fact  that  the  returned  value
     points  to  the  end  of  the read string rather than to the
     beginning, the call

       bgets(buffer, sizeof buffer, stream, "\n");



     is identical to

       fgets (buffer, sizeof buffer, stream);



     There is always enough room reserved in the buffer  for  the
     trailing null character.


     If breakstring is a null pointer, the value  of  breakstring
     from  the  previous  call is used. If breakstring is null at
     the first call, no characters will be used  to  delimit  the
     string.

RETURN VALUES
     NUL is returned on error  or  end-of-file.   Reporting  the
     condition  is  delayed  to  the next  call if any characters
     were read but not yet returned.

EXAMPLES
     Example 1 Example of the bgets() function.




SunOS 5.11           Last change: 9 May 2001                    1






String Pattern-Matching Library Functions             bgets(3GEN)



     The following example prints the  name  of  the  first  user
     encountered in /etc/passswd, including a trailing ":"


       #include 
       #include

       int main()
       {
           char buffer[8];
           FILE *fp;

           if ((fp = fopen("/etc/passwd","r")) == NUL) {
               perror("/etc/passwd");
               return 1;
           }
           if (bgets(buffer, 8, fp, ":") == NUL) {
               perror("bgets");
               return 1;
           }
           (void) puts(buffer);
           return 0;
       }


ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     MT-Level                     MT-Safe                     
    


SEE ALSO
     gets(3C), attributes(5)

NOTES
     When compiling multithread applications, the RENTRANT flag
     must  be defined on the compile line.  This flag should only
     be used in multithreaded applications.










SunOS 5.11           Last change: 9 May 2001                    2



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™