您的位置:首页 > 其它

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

2018-03-05 21:32 453 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐