《c程序设计语言》读书笔记--统计总的字符数,打印能打印的最多字符

#include <stdio.h>

#define MAXLINE 10

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


int main()
{
    int len;
    int max;
    char line[MAXLINE] = {0};
    char longest[MAXLINE] = {0};

    max = 0;

    while((len = getline(line,MAXLINE)) > 0)
        if(len > max)
        {
            max = len;
            copy(longest,line);
        }
    if(max > 0)
        printf("%d  %s
",max,longest);
    return 0;
}

int getline(char s[],int lim)

{
    int c,i;

    for(i = 0; (c=getchar()) != EOF && c != '
';i++)
    {
		if(i < lim-2)
        s[i] = c;
    }
    if(c == '
')
    {
		if(i >= lim-2)
		{
			s[lim-2] = '
';		
			s[lim-1] = '';
		}
    }

    return i;
}

void copy(char to[],char from[])
{
    int i = 0;

    while((to[i] = from[i]) != '')
        i++;
}

比较蛋疼!统计总的字符数,打印能打印的最多字符。


原文地址:https://www.cnblogs.com/batteryhp/p/5020490.html