主函数返回一个0有什么用?

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:11:30
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */

int getline(char line[], int maxline);
void copy(char to[], char from[]);

/* print the longest input line */
main()
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */

max = 0;
while ((len = getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
printf("%s", longest);
return 0;
}

/* getline: read a line into s, return length */
int getline(char s[],int lim)
{
int c, i;

主函数的返回值是返回给操作系统的,用来判断程序是否正常执行完毕。返回0表示正常结束,返回非0值表示程序异常中止。

如果是主函数的话.没有什么用!!!但是如果一个函数没写着void,即不返回的话.就一定要有return.

C好象不太严禁吧.

判断程序是否正常执行完!

条件判断啊