[cpp] view plaincopyprint?
#include
#define MAXLINE 1000
int getline(char s[] , int lim) ;
int remove(char s[]) ;
main()
{
char line[MAXLINE] ;
while(getline(line,MAXLINE) > 0)
if(remove(line) > 0)
printf("%s",line) ;
}
int getline(char s[] , int lim)
{
int c,i,j ;
i = 0 ;
j = 0 ;
while((c = getchar()) != EOF && c != '\n' ){
if(j < lim - 2){
s[j] = c ;
++ j ;
}
++ i ;
}
if(c == '\n'){
s[j] = c ;
++ j;
++ i;
}
s[j] = '\0' ;
return i ;
}
int remove(char s[])
{
int i ;
i = 0 ;
while(s[i] != '\n')
++ i ;
-- i ;
for( ;i > 0 && s[i] == ' ' || s[i] == '\t' ; --i);
if(i >= 0){
++ i ;
s[i] = '\n' ;
++ i ;
s[i] = '\0' ;
}
return i ;
}
阅读(769) | 评论(0) | 转发(0) |