0

有一个奇怪的问题

sprintf(tmp, "\"%s\"", filename);

我希望输出是

"filename"

但相反我得到

\"filename\"

这里发生了什么?

==============================

extern "C" void __export __pascal MyFunc(LPTSTR m_avi, LPTSTR m_mpg)
{
  int frameRate = 20;
  char szAVI[MAX_PATH], szMPG[MAX_PATH];

#ifdef UNICODE
  wcstombs(szAVI, m_avi, _tcslen(m_avi) + 1);
  wcstombs(szMPG, m_mpg, _tcslen(m_mpg) + 1);
#else
  strcpy(szAVI, m_avi);
  strcpy(szMPG, m_mpg);
#endif

  //Call to ffmpeg.exe
  char cmdline[1000] = "ffmpeg ", tmp[50];

  //Overwrite without asking
  strcat(cmdline, "-y ");

  //Input file
  sprintf(tmp, "-i \"%s\" ", szAVI);
  strcat(cmdline, tmp);

  //Lock output at 20 frames per second
  sprintf(tmp, "-r %i ", frameRate);
  strcat(cmdline, tmp);

  //Output file
  sprintf(tmp, "\"%s\"", szMPG);
  strcat(cmdline, tmp);

  WinExec(cmdline, SW_HIDE);
}
4

1 回答 1

2

由于您显示的代码实际上并没有产生任何输出,我怀疑您正在谈论的“输出”来自您的调试器,您试图在调用之前检查数组的值WinExec

调试器通常使用被调试语言的语法来显示变量的值。在这种情况下,调试器显示字符串变量包含引号。由于引号在 C++ 中是特殊的,因此调试器还显示反斜杠以指示引号是字符串内容的一部分,而不是表示字符串值的开始或结束。

If you're seeing backslashes in the debugger, then everything's fine. If you're seeing backslashes printed out or displayed somewhere in your program, then you need to go look at that code since the code here in the question doesn't display anything.

于 2012-06-18T14:12:35.417 回答