我试图理解K&R书中的例1.9,但我不知道如何发送EOF.一些消息来源提到了Ctr + Z,但这只是终止了程序.我以某种方式设法发送EOF与Enter和Ctrl + Z的组合,也许Ctrl + V,但我无法重现它.
#include <stdio.h>
#define MAXLINE 1000
main()
{
int len;
int max;
char line[MAXLINE];
char save[MAXLINE];
max = 0;
while((len = getline_my(line, MAXLINE)) > 0)
if(len > max) {
max = len;
copy(line, save);
}
if(max > 0)
printf("%s", save);
}
getline_my(s, lim)
char s[];
int lim;
{
int c, i;
for(i=0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; i++)// As long as the condition is fulfilled
s[i] …Run Code Online (Sandbox Code Playgroud) 我在 Fedora 20 上使用 Anjuta 和 gdb 并创建了一个 C Makefile 项目。代码如下所示:
#include <stdio.h>
int main (void)
{
° printf ("1");
° printf ("2");
° printf ("3");
return (0);
}
Run Code Online (Sandbox Code Playgroud)
° 表示我在那个位置设置了一个断点。
现在,当我调试代码时,没有输出,而当前行是这些 printf 函数之一。只有当我退出 main '123' 时,终端中才会出现。
如果我将 \n 添加到第二个 printf 参数,那么当我从断点 2 移动到第三个断点时,输出会出现 '12'。
我正在尝试使用CppUnit来测试一个只在第一次调用时才执行某些代码的方法.
class CElementParseInputTests: public CppUnit::TestFixture {
private:
CElement* element;
public:
void setUp() {
element = new CElement();
}
void tearDown() {
delete element;
}
void test1() {
unsigned int parsePosition = 0;
CPPUNIT_ASSERT_EQUAL(false, element->parseInput("fäil", parsePosition));
}
void test2() {
unsigned int parsePosition = 0;
CPPUNIT_ASSERT_EQUAL(false, element->parseInput("pass", parsePosition));
}
Run Code Online (Sandbox Code Playgroud)
我想测试的递归方法:
bool CElement::parseInput(const std::string& input, unsigned int& parsePosition) {
static bool checkedForNonASCII = false;
if(!checkedForNonASCII) {
std::cout << "this should be printed once for every test case" << std::endl;
[...]
checkedForNonASCII = …Run Code Online (Sandbox Code Playgroud)