我正在尝试一个基本程序setvbuf
:
int main(int argc, char **argv) {
FILE * fp;
char buffer[1024];
fp = fopen("~/my.txt", "w");
setvbuf(fp, buffer, _IOFBF, sizeof(buffer));
return EXIT_SUCCESS;
}
当我运行程序时,我遇到了分段错误setvbuf
:
Breakpoint 1, main (argc=0, argv=0x20) at ../my.c:13
13 int main(int argc, char **argv) {
(gdb) n
18 fp = fopen("~/my.txt", "w");
(gdb) n
20 setvbuf(fp, buffer, _IOFBF, sizeof(buffer));
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
我的环境是:
$ uname -a
CYGWIN_NT-6.1 myhost 1.7.25(0.270/5/3) 2013-08-31 20:37 x86_64 Cygwin
$ gcc --version
gcc (GCC) 4.8.1