C程序设计语言 1-16 1-17 1-18 1-19

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40712616/article/details/79451401

c复习第二弹!

主要是根据1-16~1-19大致题意写的,具体要求有出入

#include <stdio.h>
/********************
 * 练习 1-16 ~ 1-19
 * ******************/

#define MIXNUMBER 1000

int getlines(char line[]);
void copy(char to[],char from[]);
void copy_back(char to[],char from[],int len); //逆序输出,len为输出\入长度

void main()
{
    int max = 0;
    int len = 0;
    int c;

    char line[MIXNUMBER];
    char maxWorld[MIXNUMBER];
    while((len = getlines(line)) > 0)
   {
       if(len > max){
           max = len;
           //copy( maxWorld,line);
           copy_back( maxWorld,line,max);
       }
    printf("\n %d\n",max);  
    printf("%s\n",maxWorld);
    }

}

int getlines(char s[])
{
    int i,c;
    for(i = 0; i < MIXNUMBER -1&&(c =getchar())!= '\n'&& c != EOF;++i)
    {
        if(c == ' ' || c == '\t'){  
            i--;
        }else{
            s[i] = c;
        }
    }
    if(c ==  '\n') {
        s[i] = '\n';

    }
    s[i]='\0';
    printf("\n %d\n",i);
    return i;
}

void copy(char to[],char from[])
{
    int i;
    i = 0;
    while((to[i] = from[i]) != '\0') ++i;
}
void copy_back(char to[],char from[],int len)
{
    int i;
    i = 0;
    while((to[--len] = from[i]) != '\0') ++i;
}

猜你喜欢

转载自blog.csdn.net/qq_40712616/article/details/79451401
今日推荐