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


C++ Sprintf函数代码示例

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


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

示例1: switch

void ScopeI::wakeupRaw(int) {
  //  dbx("wakeup raw");
  try {
    int r = sleeper->poll();
    switch (r) {
    case Wakeup::Trig: // fall through to Poll stuff.
      if (seentrig) {
	nexttrig = rawsf->aux()->trig.t_latest  + rawsf->first();
	seentrig = false;
      }
    case Wakeup::Poll:
    {
      if (!rawpoll) {
	rawpoll=true;
	setStatus(rawstatus, Wakeup::Poll, rawpoll, rawsf);
      }
      if (freezeflag->isChecked())
	break;
      timeref_t sftime = rawsf->latest();
      timeref_t next;
      if (trigflag->isChecked()) {
	next = nexttrig + scopes->period() - pretrig->value()*FREQKHZ;
	if (next > sftime || next==scopes->latest())
	  break;
	seentrig = true;
      } else {
	timeref_t last = scopes->latest();
	next = last + scopes->period();
	if (next > sftime)
	  break;
	if (sftime - next > MAXLAG)
	  next = sftime; // lose some (partial) frames
	//      sdbx("Scope: refresh %.3f",next/25000.0);
      }
      scopes->refresh(next);
      timeref_t ival = next - scopes->first();
      time->setText(Sprintf("%.3f s",ival/1000./FREQKHZ).c_str());
    } break;
    case Wakeup::Start: {
      freeze(false);
      freezeflag->setChecked(false);
      rawpoll=false;
      setStatus(rawstatus, Wakeup::Start, rawpoll, rawsf);
      copybasics();
      scopes->restart();
      nexttrig = scopes->latest(); seentrig = true;
    } break;
    case Wakeup::Stop:
      rawpoll=false;
      setStatus(rawstatus, Wakeup::Stop, rawpoll, rawsf);
      break;
    default: break;
    }
  } catch (Expectable const &e) {
    // probably EOF
    e.report();
    reopen_raw();
  }
}
开发者ID:maru-n,项目名称:meabench_robot,代码行数:59,代码来源:Scope.C

示例2: sdbx

void FreezeInfo::scrollTo(int dt_ms) {
  timeref_t endtime = t0 + (dt_ms+width_ms)*FREQKHZ;
  sdbx("freezeinfo scrollto: %i - endtime=%Li",dt_ms,endtime);
  backend->refresh(endtime);
  timeref_t ival = endtime - backend->first();
  timereport->setText(Sprintf("%.3f s",ival/1000./FREQKHZ).c_str());
  sdbx("freezeinfo scrollto: refresh done");
}
开发者ID:maru-n,项目名称:meabench_robot,代码行数:8,代码来源:FreezeInfo.C

示例3: outrip

/*
outrip(winid, int)
	    -- The tombstone code.  If you want the traditional code use
	       genl_outrip for the value and check the #if in rip.c.
*/
void gnome_outrip(winid wid, int how)
{
    /* Follows roughly the same algorithm as genl_outrip() */
    char buf[BUFSZ];
    char ripString[BUFSZ]="\0";
    extern const char *killed_by_prefix[];

    /* Put name on stone */
    Sprintf(buf, "%s\n", plname);
    Strcat(ripString, buf);

    /* Put $ on stone */
    Sprintf(buf, "%ld Au\n",
#ifndef GOLDOBJ
            u.ugold);
#else
            done_money);
#endif
    Strcat(ripString, buf);

    /* Put together death description */
    switch (killer_format) {
    default:
        impossible("bad killer format?");
    case KILLED_BY_AN:
        Strcpy(buf, killed_by_prefix[how]);
        Strcat(buf, an(killer));
        break;
    case KILLED_BY:
        Strcpy(buf, killed_by_prefix[how]);
        Strcat(buf, killer);
        break;
    case NO_KILLER_PREFIX:
        Strcpy(buf, killer);
        break;
    }
    /* Put death type on stone */
    Strcat(ripString, buf);
    Strcat(ripString, "\n");

    /* Put year on stone */
    Sprintf(buf, "%4d\n", getyear());
    Strcat(ripString, buf);

    ghack_text_window_rip_string( ripString);
}
开发者ID:chasonr,项目名称:unnethack-i18n,代码行数:51,代码来源:gnbind.c

示例4: sitoa

static char *
sitoa(int a)
{
	static char buf[13];

	Sprintf(buf, (a < 0) ? "%d" : "+%d", a);
	return (buf);
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:8,代码来源:hack.objnam.c

示例5: Sprintf

Psym *hoc_getsym(const char* cp) {
	Symbol *sp, *sym;
	Symlist *symlist = (Symlist *)0;
	Inst *last, *pcsav;
	int i, n;
	char s[256];
	Psym *p=0;

	Sprintf(s, "{%s}\n", cp);
	sp = hoc_install("", PROCEDURE, 0., &symlist);
	sp->u.u_proc->defn.in = STOP;
	sp->u.u_proc->list = (Symlist *)0;
	sp->u.u_proc->nauto = 0;
	n = hoc_xopen_run(sp, s);
	last = (Inst *)sp->u.u_proc->defn.in + n;
	if (n < 5 || last[-3].pf != hoc_eval) {
		hoc_execerror(s, " not a variable");
	}
	last[-3].in = STOP;	/*before doing last EVAL*/
	pcsav = hoc_pc;
	hoc_execute(sp->u.u_proc->defn.in);
	hoc_pc = pcsav;
	
	sym = hoc_spop();
	switch(sym->type) {
	case UNDEF:
		hoc_execerror(s, " is undefined");
	case VAR:
		if (ISARRAY(sym)) {
			Arrayinfo* a;
			if (sym->subtype == NOTUSER) {
				a = OPARINFO(sym);
			}else{
				a = sym->arayinfo;
			}
			p = (Psym *)emalloc((unsigned)(sizeof(Psym) +
				a->nsub));
			p->arayinfo = a;
			++a->refcount;
			p->nsub = a->nsub;
			for (i=p->nsub; i > 0;) {
				p->sub[--i] = hoc_xpop();
			}
		} else {
			p = (Psym *)emalloc(sizeof(Psym));
			p->arayinfo = 0;
			p->nsub = 0;
		}
		p->sym = sym;
		break;
	case AUTO:
		hoc_execerror(s, " is local variable");
	default:
		hoc_execerror(s, " not a variable");
	}
	hoc_free_list(&symlist);
	return p;	
}
开发者ID:nrnhines,项目名称:nrn,代码行数:58,代码来源:getsym.c

示例6: SetWindowText

INT_PTR CALLBACK CClassicCopyFolder::DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	if (uMsg==WM_INITDIALOG)
	{
		SetWindowText(hwndDlg,FindTranslation(L"Folder.Title",L"Confirm Folder Replace"));
		CClassicCopyFolder *pThis=(CClassicCopyFolder*)lParam;
		wchar_t text[2048];
		// find the link control and get its text
		HWND link=FindWindowEx(pThis->m_Original,NULL,WC_LINK,NULL);
		if (link)
			GetWindowText(link,text,_countof(text));
		else
			text[0]=0;
		Strcat(text,_countof(text),L"\r\n\r\n");
		Strcat(text,_countof(text),FindTranslation(L"Folder.Prompt",L"Do you still want to move or copy the folder?"));
		SetDlgItemText(hwndDlg,IDC_STATICFNAME,text);

		// load icon for file conflict (146) from Shell32.dll
		HMODULE hShell32=GetModuleHandle(L"Shell32.dll");
		pThis->m_Icon=LoadIcon(hShell32,MAKEINTRESOURCE(146));
		if (pThis->m_Icon)
			SendDlgItemMessage(hwndDlg,IDC_STATICICON1,STM_SETICON,(LPARAM)pThis->m_Icon,0);

		// set the localized text
		SetDlgItemText(hwndDlg,IDOK,FindTranslation(L"Copy.Yes",L"&Yes"));
		SetDlgItemText(hwndDlg,IDNO,FindTranslation(L"Copy.No",L"&No"));
		if (GetDlgItem(hwndDlg,IDYES))
			SetDlgItemText(hwndDlg,IDYES,FindTranslation(L"Copy.YesAll",L"Yes to &All"));
		if (GetDlgItem(hwndDlg,IDCANCEL))
			SetDlgItemText(hwndDlg,IDCANCEL,FindTranslation(L"Copy.Cancel",L"Cancel"));
		Sprintf(text,_countof(text),L"<a>%s</a>",FindTranslation(L"Copy.More",L"&More..."));
		SetDlgItemText(hwndDlg,IDC_LINKMORE,text);
		PostMessage(hwndDlg,WM_BRINGFOREGROUND,0,0);
		return TRUE;
	}
	if (uMsg==WM_BRINGFOREGROUND)
	{
		// bring window to front (sometimes on Windows7 it shows up behind Explorer)
		SetForegroundWindow(hwndDlg);
		return TRUE;
	}
	if (uMsg==WM_COMMAND && (wParam==IDOK || wParam==IDYES || wParam==IDNO || wParam==IDCANCEL))
	{
		EndDialog(hwndDlg,wParam);
		return TRUE;
	}
	if (uMsg==WM_NOTIFY)
	{
		NMHDR *pHdr=(NMHDR*)lParam;
		if (pHdr->idFrom==IDC_LINKMORE && (pHdr->code==NM_CLICK || pHdr->code==NM_RETURN))
		{
			EndDialog(hwndDlg,IDC_LINKMORE);
			return TRUE;
		}
	}
	return FALSE;
}
开发者ID:VonChenPlus,项目名称:ClassicShell,代码行数:57,代码来源:ClassicCopy.cpp

示例7: done_in_by

void
done_in_by(struct monst *mtmp)
{
static char buf[BUFSZ];
	pline("You die ...");
	if(mtmp->data->mlet == ' '){
		Sprintf(buf, "the ghost of %s", (char *) mtmp->mextra);
		killer = buf;
	} else if(mtmp->mnamelth) {
		Sprintf(buf, "%s called %s",
			mtmp->data->mname, NAME(mtmp));
		killer = buf;
	} else if(mtmp->minvis) {
		Sprintf(buf, "invisible %s", mtmp->data->mname);
		killer = buf;
	} else killer = mtmp->data->mname;
	done("died");
}
开发者ID:blakeney,项目名称:slack,代码行数:18,代码来源:hack.end.c

示例8: sitoa

char *
sitoa(int n)		/* make a signed digit string from a number */
      
{
    Static char buf[13];

    Sprintf(buf, (n < 0) ? "%d" : "+%d", n);
    return buf;
}
开发者ID:chasonr,项目名称:unnethack-i18n,代码行数:9,代码来源:hacklib.c

示例9: ftp_command

static Str
ftp_command(FTP ftp, char *cmd, char *arg, int *status)
{
    Str tmp;

    if (!ftp->host)
        return NULL;
    if (cmd) {
        if (arg)
            tmp = Sprintf("%s %s\r\n", cmd, arg);
        else
            tmp = Sprintf("%s\r\n", cmd);
        fwrite(tmp->ptr, sizeof(char), tmp->length, ftp->wf);
        fflush(ftp->wf);
    }
    if (!status)
        return NULL;
    *status = -1;		/* error */
    tmp = StrISgets(ftp->rf);
    if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
            IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ')
        sscanf(tmp->ptr, "%d", status);

    if (tmp->ptr[3] != '-')
        return tmp;
    /* RFC959 4.2 FTP REPLIES */
    /* multi-line response start */
    /*
     * Thus the format for multi-line replies is that the
     * first line will begin with the exact required reply
     * code, followed immediately by a Hyphen, "-" (also known
     * as Minus), followed by text.  The last line will begin
     * with the same code, followed immediately by Space <SP>,
     * optionally some text, and the Telnet end-of-line code. */
    while (1) {
        tmp = StrISgets(ftp->rf);
        if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
                IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') {
            sscanf(tmp->ptr, "%d", status);
            break;
        }
    }
    return tmp;
}
开发者ID:kumakichi,项目名称:w3m,代码行数:44,代码来源:ftp.c

示例10: editMailcap

void
editMailcap(char *mailcap, struct parsed_tagarg *args)
{
    TextList *t = newTextList();
    TextListItem *ti;
    FILE *f;
    Str tmp;
    char *type, *viewer;
    struct parsed_tagarg *a;
    bool delete_it;

    if ((f = fopen(mailcap, "rt")) == NULL)
	bye("Can't open", mailcap);

    while (tmp = Strfgets(f), tmp->length > 0) {
	if (tmp->ptr[0] == '#')
	    continue;
	Strchop(tmp);
	extractMailcapEntry(tmp->ptr, &type, &viewer);
	delete_it = false;
	for (a = args; a != NULL; a = a->next) {
	    if (!strcmp(a->arg, "delete") && !strcmp(a->value, type)) {
		delete_it = true;
		break;
	    }
	}
	if (!delete_it)
	    pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr);
    }
    type = tag_get_value(args, "newtype");
    viewer = tag_get_value(args, "newcmd");
    if (type != NULL && *type != '\0' && viewer != NULL && *viewer != '\0')
	pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr);
    fclose(f);
    if ((f = fopen(mailcap, "w")) == NULL)
	bye("Can't write to", mailcap);

    for (ti = t->first; ti != NULL; ti = ti->next)
	fputs(ti->ptr, f);
    fclose(f);
    printf("Content-Type: text/plain\n");
    printf("w3m-control: BACK\nw3m-control: BACK\n");
    printf("w3m-control: REINIT MAILCAP\n");
}
开发者ID:dafyddcrosby,项目名称:sw3m,代码行数:44,代码来源:w3mhelperpanel.c

示例11: add_news_message

static void
add_news_message(Str str, int index, char *date, char *name, char *subject,
		 char *mid, char *scheme, char *group)
{
    time_t t;
    struct tm *tm;

    name = name_from_address(name, 16);
    t = mymktime(date);
    tm = localtime(&t);
    Strcat(str,
	   Sprintf("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s",
		   index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name)));
    if (group)
	Strcat(str, Sprintf("<td><a href=\"%s%s/%d\">%s</a>\n", scheme, group,
			    index, html_quote(subject)));
    else
	Strcat(str, Sprintf("<td><a href=\"%s%s\">%s</a>\n", scheme,
			    html_quote(file_quote(mid)), html_quote(subject)));
}
开发者ID:dafyddcrosby,项目名称:sw3m,代码行数:20,代码来源:news.c

示例12: FmtLoadStr

UnicodeString FmtLoadStr(intptr_t Id, fmt::ArgList args)
{
  UnicodeString Fmt = GetGlobals()->GetMsg(Id);
  if (!Fmt.IsEmpty())
  {
    UnicodeString Result = Sprintf(Fmt, args);
    return Result;
  }
  DEBUG_PRINTF("Unknown resource string id: %d\n", Id);
  return UnicodeString();
}
开发者ID:michaellukashov,项目名称:Far-NetBox,代码行数:11,代码来源:FormatUtils.cpp

示例13: getdate

char *
getdate()
{
	static char datestr[7];
	register struct tm *lt = getlt();

	Sprintf(datestr, "%2d%2d%2d",
		lt->tm_year, lt->tm_mon + 1, lt->tm_mday);
	if(datestr[2] == ' ') datestr[2] = '0';
	if(datestr[4] == ' ') datestr[4] = '0';
	return(datestr);
}
开发者ID:nethack-variants,项目名称:variants,代码行数:12,代码来源:pcunix.c

示例14: localCookie

/* setup cookie for local CGI */
Str
localCookie()
{
    char hostname[256];

    if (Local_cookie)
	return Local_cookie;
    gethostname(hostname, 256);
    srand48((long)New(char) + (long)time(NULL));
    Local_cookie = Sprintf("%[email protected]%s", lrand48(), hostname);
    return Local_cookie;
}
开发者ID:albfan,项目名称:w3m,代码行数:13,代码来源:local.c

示例15: PutOctalString

static void PutOctalString(Stream& out, const char *b, const char *e, bool split = false)
{
	out.Put('\"');
	int64 start = out.GetPos();
	while(b < e) {
		if(split && out.GetPos() >= start + 200u) {
			out.Put("\"\r\n\t\"");
			start = out.GetPos();
		}
		if((byte)*b >= ' ' && *b != '\x7F' && *b != '\xFF') {
			if(*b == '\\' || *b == '\"' || *b == '\'')
				out.Put('\\');
			out.Put(*b++);
		}
		else if(IsDigit(b[1]))
			out.Put(Sprintf("\\%03o", (byte)*b++));
		else
			out.Put(Sprintf("\\%o", (byte)*b++));
	}
	out.Put('\"');
}
开发者ID:dreamsxin,项目名称:ultimatepp,代码行数:21,代码来源:ImlFile.cpp


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