1. Turbo C程序的一般组成部分
Turbo C 2.0 象其它语言一样按其规定的格式和提供的语句由用户编写应用程
序。 请看下面一段Turbo C源程序。 例1:
/*Example program of Turbo C*/
#include /*包含文件说明*/
void lgc(void);/*子函数说明*/
char answer;/*定义全程变量*/
int main()/*主函数定义*/
{
char a;/*定义局部变量*/
clrscr();
gotoxy(12,3);
puts("Welcome to use Turbo C2.0!");
gotoxy(15,13);
printf("--Exit");
gotoxy(15,15);
printf("--Continue");
while(1)
{
a=getch();
if(a==27)
break;
if(a==13)
{
lgc();
if(answer==’y’||answer==’Y’)
{
gotoxy(23,14);
puts("Please Write to the Company");
getch();
break;
}
}
}
return(0);}void lgc(void){
clrscr();
gotoxy(12,8);
printf("The Excellent Selection!");
gotoxy(21,12);
printf("Do you have any question?(Y/N)");
answer=getche();}
由例子程序可以看出,Turbo C源程序主要有以下几个特点:1. 程序一般用小写
字母书写;2. 大多数语句结尾必须要用";"作为终止符,否则Turbo C 不认为该语句
结束;3. 每个程序必须有一个而且只能有一个称作主函数的main()函数;4. 每个程
序体(主函数和每个子函数,如上例中的main()函数和sub()函数)必须用一对花括号"
{"和"}"括起来;5. 一个较完整的程序大致包括:包含文件(一组#include<*.h>语句)、
用户函数说明部分、全程变量定义、主函数和若干子函数组成。在主函数和子函数