fork download
  1. /* Write a Program to remove the trailing blanks and tabs from each input line
  2.   and to delete entirely blank lines */
  3.  
  4. #include<stdio.h>
  5. #define MAXLINE 1000
  6.  
  7. int mgetline(char line[],int lim);
  8. int removetrail(char rline[]);
  9.  
  10. int main(void)
  11. {
  12. int len;
  13. char line[MAXLINE];
  14.  
  15. while((len=mgetline(line,MAXLINE))>0)
  16. if(removetrail(line) > 0)
  17. printf("%s",line);
  18.  
  19. return 0;
  20. }
  21.  
  22. int mgetline(char s[],int lim)
  23. {
  24. int i,c;
  25.  
  26. for(i=0;i<lim-1 && (c=getchar())!=EOF && c!='\n';++i)
  27. s[i] = c;
  28. if( c == '\n')
  29. {
  30. s[i]=c;
  31. ++i;
  32. }
  33. s[i]='\0';
  34.  
  35. return i;
  36. }
  37.  
  38. /* To remove Trailing Blanks,tabs. Go to End and proceed backwards removing */
  39.  
  40. int removetrail(char s[])
  41. {
  42. int i;
  43.  
  44. for(i=0; s[i]!='\n'; ++i)
  45. ;
  46. --i; /* To consider raw line without \n */
  47.  
  48. for(i >0; ((s[i] == ' ') || (s[i] =='\t'));--i)
  49. ; /* Removing the Trailing Blanks and Tab Spaces */
  50.  
  51. if( i >= 0) /* Non Empty Line */
  52. {
  53. ++i;
  54. s[i] = '\n';
  55. ++i;
  56. s[i] = '\0';
  57. }
  58. return i;
  59. }
Success #stdin #stdout 0s 4388KB
stdin
This Is Not    True.

That    Is True.
stdout
This Is Not    True.
That    Is True.