• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

12.9.3 Interacting with foreign streams
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Foreign Language Interface
        • Foreign access to Prolog IO streams
          • Interacting with foreign streams
            • Sset_timeout()
            • Sunit_size()
            • Sputc()
            • Sgetc()
            • Sfgetc()
            • Sungetc()
            • Sputcode()
            • Sgetcode()
            • Speekcode()
            • Sputw()
            • Sgetw()
            • Sfread()
            • Sfwrite()
            • Sfeof()
            • Sfpasteof()
            • Ssetlocale()
            • Sflush()
            • Ssize()
            • Sseek()
            • Sseek64()
            • Stell()
            • Stell64()
            • Sclose()
            • Sgcclose()
            • Sfgets()
            • Sgets()
            • Sread_pending()
            • Spending()
            • Sfputs()
            • Sputs()
            • Sfprintf()
            • SfprintfX()
            • Sprintf()
            • Svprintf()
            • Ssprintf()
            • Ssnprintf()
            • SsnprintfX()
            • Svsprintf()
            • Svsnprintf()
            • Sdprintf()
            • SdprintfX()
            • Svdprintf()
            • Slock()
            • StryLock()
            • Sunlock()
            • Sfileno()
            • Swinsock()
            • Sclosehook()
            • Sset_filter()
            • Ssetbuffer()
            • Running a child process on a Windows terminal
            • Writing Prolog terms to foreign streams
    • Packages
Availability:C-language interface function
int Sfprintf(IOSTREAM *s, const char *fm, ...)
Similar to POSIX fprintf(). This function largely accepts the same % escape sequences. The % character is followed by numeric arguments and modifier characters. The generic format of this is described by the regular expression [+-0 #]*(\d*|\*)(.(\d*|\*))?. Here, + implies right alignment, - left alignment, 0 0-padding and, a space white-space padding and # modified output. The two optional numerical arguments are separated by a full stop and may be * to get them from the argument list. The first numerical argument specifies the field width and the second the precision for floating point numbers.

This sequence is followed by optional type information. For integers this is one of l (long), ll (long long) or z (size_t). For strings this is one of L (ISO Latin 1), U (UTF-8) or W (wchar_t*).

Finally we come to the format specifier. This is one of

  • %
    Emit the % character itself.
  • c
    Emit a Unicode code point.
  • p
    Emit a pointer.
  • d
  • i
    Emit a a signed integer as decimal. The l (long), ll (long long) or z (size_t) denote the size.
  • o
  • u
  • x
  • X
    Emit a a unsigned integer as octal, decimal or hexadecimal.
  • f
  • e
  • E
  • g
  • G
    Emit a double.
  • s
    Emit a 0-terminated string.
  • As
    Emit a string as a Prolog atom, i.e., surrounded by single quotes and using the character escape syntax if that is needed to read the text back, e.g., SfprintfX(s, "%UAs", "a b") emits ’a b’. The string is 0-terminated unless the precision is given, in which case it is the length of the string in char or, for W, wchar_t elements. Unlike the other specifiers this one writes to s directly, which implies the field width does not apply to it. It is intended for the write() function of a blob; see section section 12.4.10.
  • Unlike the POSIX fprintf(), this function, and the related functions (Svprintf(), etc.) returns the number of characters written. Due to multibyte encodings the number of bytes written can be more. On error, it returns a negative value; in some cases there is extra information (e.g., in errno) but it cannot be relied on.

    Each call to Sfprintf() is atomic in the sense that another thread that calls Sfprintf() on the same stream will block. If you wish to do a series of print statements without any other thread interleaving, you should call PL_acquire_stream() and use its returned IOSTREAM* value, then call PL_release_stream() at the end of the print statements.

    ClioPatria (version V3.1.1-59-g7b9a7a3)