|
学习C时候,一个书中的例子,我原封不动的抄的.编译成功,但是执行a.out时候,出现错误并返回,错误提示为[段错误(core dumped)].因为书中的那个例子也是在unix环境下编程的,所以我想应该不会是程序的问题.我特别在win下面也做了编译,是成功的.并且可执行.
程序本身很简单,如下:
[code]
#include <stdio.h>
int main(void)
{
char c1, c2, c3;
int i;
float x;
double y;
printf("\n%s\n%s",
"Input three characters,"
"an int, a float, and a double: ");
scanf("%c%c%c%d%f%lf", &c1, &c2, &c3, &i, &x, &y);
printf("\nHere is the data that you typed in:\n");
printf("%3c%3c%3c%5d%17e%17e\n\n", c1, c2, c3, i, x, y);
return 0;
}
[code]
希望大家帮忙.说下原因和解决办法~~.谢谢
----------------------%<---------------------
补充一下.更有意思的事情发生了.
我把最后那个printf分成2行来写,即:
[code]
printf("%3c%3c%3c%5d\n\n", c1, c2, c3, i);
printf("%17e%17e\n\n", x, y);
[code]
这样就什么事情都没有了.一切正常..真是令人很费解阿~~ |
|