2014年05月13日

来源:互联网 发布:呱呱社区软件 编辑:程序博客网 时间:2024/04/25 08:03

practice 1-18:delete blank or'\t' at the end of one line ofwords,also before the \n

#include
#define MAXWORD 1000

int getline(char line[],int maxline);
int removes(char s[]);
int main()
{
 char line[MAXWORD];
 int len;
 while((len=getline(line,MAXWORD))>0)
  if(removes(line)>0)
   printf("%s",line);
 return 0;
}

int getline(char s[],int lim)
{
 int c,i;

 for(i=0;i
 {
  s[i]=c;
  
 }
 if(c=='\n')
 {
  s[i]=c;
  
  ++i;
 }
 s[i]='\0';
 return i;
}
int removes(char s[])
{
 int i=0;
 while(s[i]!='\n')
  ++i;
 --i;
 while(i>=0&&(s[i]==''||s[i]=='\t'))
  --i;
 if(i>=0)
 {
  ++i;
  s[i]='\n';
  ++i;
  s[i]='\0';
 }
 return i;
}

0 0
原创粉丝点击