zoukankan      html  css  js  c++  java
  • 《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++;
    }
    
    比较蛋疼!统计总的字符数,打印能打印的最多字符。
    
    


  • 相关阅读:
    8.3学习日志
    8.2学习日志
    8.1学习日志
    Chapter 2
    未命名 1
    pugixml
    C++使用Json作为数据包装格式的通信
    项目FAQ
    xcode语法高亮插件
    【转】jsoncpp在xcode中的使用
  • 原文地址:https://www.cnblogs.com/batteryhp/p/5020490.html
Copyright © 2011-2022 走看看