当前位置: 首页>>代码示例>>C++>>正文


C++ Snprintf函数代码示例

本文整理汇总了C++中Snprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ Snprintf函数的具体用法?C++ Snprintf怎么用?C++ Snprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Snprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Snprintf

 void OptionsList::PrintUserOptions(std::string& list) const
 {
   list.erase();
   char buffer[256];
   Snprintf(buffer, 255, "%40s   %-20s %s\n", "Name", "Value", "used");
   list += buffer;
   for (std::map< std::string, OptionValue >::const_iterator p = options_.begin();
        p != options_.end();
        p++ ) {
     if (!p->second.DontPrint()) {
       const char yes[] = "yes";
       const char no[] = "no";
       const char* used;
       if (p->second.Counter()>0) {
         used = yes;
       }
       else {
         used = no;
       }
       Snprintf(buffer, 255, "%40s = %-20s %4s\n", p->first.c_str(),
                p->second.Value().c_str(), used);
       list += buffer;
     }
   }
 }
开发者ID:athrpf,项目名称:ipopt-trunk,代码行数:25,代码来源:IpOptionsList.cpp

示例2: PrintReal

/*
 * Math library extensions to AG_Label(3).
 */
static void
PrintReal(AG_Label *lbl, char *s, size_t len, int fPos)
{
	M_Real r = AG_LABEL_ARG(lbl,M_Real);
#if defined(QUAD_PRECISION)
	Snprintf(s, len, "%llf", r);
#else
	Snprintf(s, len, "%f", r);
#endif
}
开发者ID:adsr,项目名称:agar,代码行数:13,代码来源:m_math.c

示例3: bye

static char *make_nonce(const struct timeval *tv)
{
    char *buf = NULL;
    size_t size = 0, offset = 0;
    MD5_CTX md5;
    unsigned char hashbuf[MD5_DIGEST_LENGTH];
    char hash_hex[MD5_DIGEST_LENGTH * 2 + 1];
    char time_buf[32];

    /* Crash if someone forgot to call http_digest_init_secret. */
    if (!secret_initialized)
        bye("Server secret not initialized for Digest authentication. Call http_digest_init_secret.");

    Snprintf(time_buf, sizeof(time_buf), "%lu.%06lu",
        (long unsigned) tv->tv_sec, (long unsigned) tv->tv_usec);

    MD5_Init(&md5);
    MD5_Update(&md5, secret, sizeof(secret));
    MD5_Update(&md5, ":", 1);
    MD5_Update(&md5, time_buf, strlen(time_buf));
    MD5_Final(hashbuf, &md5);
    enhex(hash_hex, hashbuf, sizeof(hashbuf));

    strbuf_sprintf(&buf, &size, &offset, "%s-%s", time_buf, hash_hex);

    return buf;
}
开发者ID:TomSellers,项目名称:nmap,代码行数:27,代码来源:http_digest.c

示例4: DBG_START_METH

 void CompoundVector::PrintImpl(const Journalist& jnlst,
                                EJournalLevel level,
                                EJournalCategory category,
                                const std::string& name,
                                Index indent,
                                const std::string& prefix) const
 {
   DBG_START_METH("CompoundVector::PrintImpl", dbg_verbosity);
   jnlst.Printf(level, category, "\n");
   jnlst.PrintfIndented(level, category, indent,
                        "%sCompoundVector \"%s\" with %d components:\n",
                        prefix.c_str(), name.c_str(), NComps());
   for (Index i=0; i<NComps(); i++) {
     jnlst.Printf(level, category, "\n");
     jnlst.PrintfIndented(level, category, indent,
                          "%sComponent %d:\n", prefix.c_str(), i+1);
     if (ConstComp(i)) {
       DBG_ASSERT(name.size()<200);
       char buffer[256];
       Snprintf(buffer, 255, "%s[%2d]", name.c_str(), i);
       std::string term_name = buffer;
       ConstComp(i)->Print(&jnlst, level, category, term_name,
                           indent+1, prefix);
     }
     else {
       jnlst.PrintfIndented(level, category, indent,
                            "%sComponent %d is not yet set!\n",
                            prefix.c_str(), i+1);
     }
   }
 }
开发者ID:RobotLocomotion,项目名称:ipopt-mirror,代码行数:31,代码来源:IpCompoundVector.cpp

示例5: NCols

  void MultiVectorMatrix::PrintImpl(const Journalist& jnlst,
                                    EJournalLevel level,
                                    EJournalCategory category,
                                    const std::string& name,
                                    Index indent,
                                    const std::string& prefix) const
  {
    jnlst.Printf(level, category, "\n");
    jnlst.PrintfIndented(level, category, indent,
                         "%sMultiVectorMatrix \"%s\" with %d columns:\n",
                         prefix.c_str(), name.c_str(), NCols());

    for (Index i=0; i<NCols(); i++) {
      if (ConstVec(i)) {
        DBG_ASSERT(name.size()<200);
        char buffer[256];
        Snprintf(buffer, 255, "%s[%2d]", name.c_str(), i);
        std::string term_name = buffer;
        ConstVec(i)->Print(&jnlst, level, category, term_name,
                           indent+1, prefix);
      }
      else {
        jnlst.PrintfIndented(level, category, indent,
                             "%sVector in column %d is not yet set!\n",
                             prefix.c_str(), i);
      }
    }
  }
开发者ID:BRAINSia,项目名称:calatk,代码行数:28,代码来源:IpMultiVectorMatrix.cpp

示例6: resolve_internal

/* Internal helper for resolve and resolve_numeric. addl_flags is ored into
   hints.ai_flags, so you can add AI_NUMERICHOST. */
static int resolve_internal(const char *hostname, unsigned short port,
    struct sockaddr_storage *ss, size_t *sslen, int af, int addl_flags)
{
    struct addrinfo hints;
    struct addrinfo *result;
    char portbuf[16];
    int rc;

    ncat_assert(hostname != NULL);
    ncat_assert(ss != NULL);
    ncat_assert(sslen != NULL);

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = af;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags |= addl_flags;

    /* Make the port number a string to give to getaddrinfo. */
    rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
    ncat_assert(rc >= 0 && (size_t) rc < sizeof(portbuf));

    rc = getaddrinfo(hostname, portbuf, &hints, &result);
    if (rc != 0)
        return rc;
    if (result == NULL)
        return EAI_NONAME;
    ncat_assert(result->ai_addrlen > 0 && result->ai_addrlen <= (int) sizeof(struct sockaddr_storage));
    *sslen = result->ai_addrlen;
    memcpy(ss, result->ai_addr, *sslen);
    freeaddrinfo(result);

    return 0;
}
开发者ID:bluelineXY,项目名称:android_external_nmap,代码行数:35,代码来源:ncat_core.c

示例7: SelectUnicodeRange

static void
SelectUnicodeRange(AG_Event *event)
{
	char text[4][128];
	AG_Treetbl *tt = AG_PTR(1);
	AG_TlistItem *it = AG_PTR(2);
	struct unicode_range *range = it->p1;
	const struct unicode_range *next_range = NULL;
	Uint32 i, end;
	char *c;

	for (i = 0; i < unicodeRangeCount; i++) {
		if ((&unicodeRanges[i] == range) &&
		    (i+1 < unicodeRangeCount)) {
			next_range = &unicodeRanges[i+1];
			break;
		}
	}
	end = (next_range != NULL) ? next_range->start-1 : 0xffff;

	AG_TreetblClearRows(tt);
	
	for (i = range->start; i < end; i++) {
		if (i == 10)
			continue;
        
		/* prep column 0 */
		unitext[0] = i;
		AG_ExportUnicode(AG_UNICODE_TO_UTF8, utf8text, unitext,
		    sizeof(unitext));
		Snprintf(text[0], sizeof(text[0]), "%s", utf8text);
        
		/* prep column 1 */
		utf8seq[0] = '\0';
		for (c = &utf8text[0]; *c != '\0'; c++) {
			char s[4];
            
			Snprintf(s, sizeof(s), "%x", (unsigned char)*c);
			Strlcat(utf8seq, s, sizeof(utf8seq));
		}
		Snprintf(text[1], sizeof(text[1]), "%s", utf8seq);
        
		AG_TreetblAddRow(tt, NULL, i, "%s,%s", text[0], text[1]);
	}
}
开发者ID:adsr,项目名称:agar,代码行数:45,代码来源:uniconv.c

示例8: AG_UnitFormat

/* Format a number using the unit most suited to its magnitude. */
int
AG_UnitFormat(double n, const AG_Unit ugroup[], char *buf, size_t len)
{
	const AG_Unit *ubest;

	ubest = AG_BestUnit(ugroup, n);
	return (Snprintf(buf, len, "%.2f%s", AG_Base2Unit(n, ubest),
	    ubest->abbr[0] != '\0' ? ubest->abbr : ubest->key));
}
开发者ID:varialus,项目名称:agar,代码行数:10,代码来源:units.c

示例9: Snprintf

/* n is the size of src. dest must have at least n * 2 + 1 allocated bytes. */
static char *enhex(char *dest, const unsigned char *src, size_t n)
{
    unsigned int i;

    for (i = 0; i < n; i++)
        Snprintf(dest + i * 2, 3, "%02x", src[i]);

    return dest;
}
开发者ID:TomSellers,项目名称:nmap,代码行数:10,代码来源:http_digest.c

示例10: Snprintf

char *nsock_pcap_set_filter(pcap_t *pt, const char *device, const char *bpf) {
  struct bpf_program fcode;
  static char errorbuf[128];

  /* log_write(LOG_STDOUT, "Packet capture filter (device %s): %s\n", device, buf); */

  if (pcap_compile(pt, &fcode, (char*)bpf, 1, 0) < 0) {
    Snprintf(errorbuf, sizeof(errorbuf), "Error compiling our pcap filter: %s\n", pcap_geterr(pt));
    return errorbuf;
  }

  if (pcap_setfilter(pt, &fcode) < 0 ) {
    Snprintf(errorbuf, sizeof(errorbuf),"Failed to set the pcap filter: %s\n", pcap_geterr(pt));
    return errorbuf;
  }

  pcap_freecode(&fcode);
  return NULL;
}
开发者ID:alex-chan,项目名称:nmap,代码行数:19,代码来源:nsock_pcap.c

示例11: chat_announce_disconnect

static int chat_announce_disconnect(int fd)
{
    char buf[128];
    int n;

    n = Snprintf(buf, sizeof(buf),
        "<announce> <user%d> is disconnected.\n", fd);
    if (n >= sizeof(buf) || n < 0)
        return -1;

    return ncat_broadcast(&master_broadcastfds, &broadcast_fdlist, buf, n);
}
开发者ID:Araleii,项目名称:nmap,代码行数:12,代码来源:ncat_listen.c

示例12: init_iuctl

void init_iuctl() {
    int fd = open(QUEUE_PATH, O_WRONLY | O_CREAT | O_TRUNC, UMASK);
    if(fd < 0) {
        perror(QUEUE_PATH);
    }
    self_pid = getpid();
    assert(self_pid > 0);
    char self_pid_str[24];
    int bytes = Snprintf(self_pid_str, sizeof(self_pid_str), "%lu", self_pid);
    Write(fd, self_pid_str, bytes);
    Close(fd);
    init_iuctl(true);
}
开发者ID:wjmelements,项目名称:iu,代码行数:13,代码来源:iuctl.cpp

示例13: safe_malloc

/*
 * This is stupid. But it's just a bit of fun.
 *
 * The file descriptor of the sender is prepended to the
 * message sent to clients, so you can distinguish
 * each other with a degree of sanity. This gives a
 * similar effect to an IRC session. But stupider.
 */
static char *chat_filter(char *buf, size_t size, int fd, int *nwritten)
{
    char *result = NULL;
    size_t n = 0;
    const char *p;
    int i;

    n = 32;
    result = (char *) safe_malloc(n);
    i = Snprintf(result, n, "<user%d> ", fd);

    /* Escape control characters. */
    for (p = buf; p - buf < size; p++) {
        char repl[32];
        int repl_len;

        if (isprint((int) (unsigned char) *p) || *p == '\r' || *p == '\n' || *p == '\t') {
            repl[0] = *p;
            repl_len = 1;
        } else {
            repl_len = Snprintf(repl, sizeof(repl), "\\%03o", (unsigned char) *p);
        }

        if (i + repl_len > n) {
            n = (i + repl_len) * 2;
            result = (char *) safe_realloc(result, n + 1);
        }
        memcpy(result + i, repl, repl_len);
        i += repl_len;
    }
    /* Trim to length. (Also does initial allocation when str is empty.) */
    result = (char *) safe_realloc(result, i + 1);
    result[i] = '\0';

    *nwritten = i;

    return result;
}
开发者ID:Araleii,项目名称:nmap,代码行数:46,代码来源:ncat_listen.c

示例14: switch

const char *gai_strerror(int errcode) {
  static char customerr[64];
  switch (errcode) {
  case EAI_FAMILY:
    return "ai_family not supported";
  case EAI_NODATA:
    return "no address associated with hostname";
  case EAI_NONAME:
    return "hostname nor servname provided, or not known";
  default:
    Snprintf(customerr, sizeof(customerr), "unknown error (%d)", errcode);
    return "unknown error.";
  }
  return NULL; /* unreached */
}
开发者ID:zyan2,项目名称:ECPE170Fall,代码行数:15,代码来源:getaddrinfo.c

示例15: setenv_portable

int setenv_portable(const char *name, const char *value)
{
    char *var;
    int ret;
    size_t len;
    len = strlen(name) + strlen(value) + 2; /* 1 for '\0', 1 for =. */
    var = (char *) safe_malloc(len);
    Snprintf(var, len, "%s=%s", name, value);
    /* _putenv was chosen over SetEnvironmentVariable because variables set
       with the latter seem to be invisible to getenv() calls and Lua uses
       these in the 'os' module. */
    ret = _putenv(var) == 0;
    free(var);
    return ret;
}
开发者ID:Araleii,项目名称:nmap,代码行数:15,代码来源:ncat_exec_win.c


注:本文中的Snprintf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。