printf语句为什么不能通过调试?

来源:百度知道 编辑:UC知道 时间:2024/05/25 15:13:31
编程环境c-free 4.0,一个简单的小程序都不行
main()
{
char c1,c2;
c1=97;
c2=98;
printf("%c %c",c1,c2);
printf("%d %d",c1,c2);
}
调试结果提示:[Error] C:\Program Files\C-Free 4\temp\未命名1.cpp:6: implicit declaration of function `int printf(...)'

如何解决?

main函数需要返回值啊 第一行要改成void main()

还有 如果用printf函数 至少应该加上#include<stdio.h>
当然 可能你加了但是没写出来

#include <stdio.h>

void main()
{
char c1,c2;
c1=97;
c2=98;
printf("%c %c",c1,c2);
printf("%d %d",c1,c2);
}

这个程序应该像这样写才能编译:
#include <stdio.h>
void main()
{
char c1,c2;
c1=97;
c2=98;
printf("%c %c",c1,c2);
printf("%d %d",c1,c2);
}

缺少头文件 #include <stdio.h>
main函数前不加返回值没关系,系统会默认是整形.

没有错误.我调试出结果...看看是不是其它方面出错了

你受了TC2的影响,认为所有的C系统都可以不包含stdio.h文件而直接使用printf()、scanf()函数,实际上,除了TC2,现在的所有C系统都没有这样的规定。