我尝试从C-Primer-Plus运行示例
Listing 2.1 The first.c Program
#+BEGIN_SRC C :results output
#include <stdio.h>
int main(void) /* a simple program */
{
int num; /* define a variable called num */
num = 1; /* assign a value to num */
printf("I am a simple "); /* use the printf() function */
printf("computer.n");
printf("My favorite number is %d because it is first.n",num);
return 0;
}
#+END_SRC
它报告神秘错误为>
/tmp/babel-xEtnj6/C-src-mefAEj.c:9:15: error: stray ‘\302’ in program 9 | int main(void) /* a simple program */ | ^ /tmp/babel-xEtnj6/C-src-mefAEj.c:9:16: error: stray ‘\240’ in program 9 | int main(void) /* a simple program */ | ^ /tmp/babel-xEtnj6/C-src-mefAEj.c:9:17: error: stray ‘\302’ in program 9 | int main(void) /* a simple program */
如果删除
main()
,它将起作用
#+BEGIN_SRC C printf("Literature Programming"); #+END_SRC #+RESULTS: : Literature Programming
不幸的是,大多数C代码都封装在'main`中>]
如何使第一个示例起作用?
我试图从C-Primer-Plus清单2.1中运行一个示例.first.c程序#+ BEGIN_SRC C:结果输出#include
您可以尝试在代码块中添加:main no
#+BEGIN_SRC C :results output :main no #include <stdio.h> int main(void) /* a simple program */ { int num; /* define a variable called num */ num = 1; /* assign a value to num */ printf("I am a simple "); /* use the printf() function */ printf("computer.n"); printf("My favorite number is %d because it is first.n",num); return 0; } #+END_SRC
还请注意,还有其他有用的修饰符,例如
:flag
,:lib
,:cmdline
...有关更多详细信息,请参见Header Arguments for C, C++, D Source Code Blocks。