Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /*#include<stdio.h>
  2.  
  3. int mgetline(char s[];int lim) {
  4. int i ,c;
  5. while (i=0; i<lim-1 && ((c=getchar())!=EOF) && c!="\n"))
  6. s[i]=c;
  7. if (c=="\n" || c==EOF){
  8. s[i]="\n"
  9. i++ }
  10. s[i]="\0";
  11. return i;
  12. }
  13.  
  14. void remove (char to [] ,char from[] ) {
  15. int i,j;
  16. i=j=0;
  17. while (s[j]!="\0"){
  18.  
  19. if
  20.  
  21. int main ()
  22. {
  23.  
  24. return 0;
  25.  
  26. }*/
  27. #include<stdio.h>
  28. #define MAXLINE 1000
  29.  
  30. int mgetline(char line[],int lim);
  31. int removetrail(char rline[]);
  32.  
  33. int main(void)
  34. {
  35. int len;
  36. char line[MAXLINE];
  37.  
  38. while((len=mgetline(line,MAXLINE))>0)
  39. if(removetrail(line) > 0)
  40. printf("%s",line);
  41.  
  42. return 0;
  43. }
  44.  
  45. int mgetline(char s[],int lim)
  46. {
  47. int i,c;
  48.  
  49. for(i=0;i<lim-1 && (c=getchar())!=EOF && c!='\n';++i)
  50. s[i] = c;
  51. if( c == '\n')
  52. {
  53. s[i]=c;
  54. ++i;
  55. }
  56. s[i]='\0';
  57.  
  58. return i;
  59. }
  60.  
  61. /* To remove Trailing Blanks,tabs. Go to End and proceed backwards removing */
  62.  
  63. int removetrail(char s[])
  64. {
  65. int i;
  66.  
  67. for(i=0; s[i]!='\n'; ++i)
  68. ;
  69. --i; /* To consider raw line without \n */
  70.  
  71. for(i >0; ((s[i] == ' ') || (s[i] =='\t'));--i)
  72. ; /* Removing the Trailing Blanks and Tab Spaces */
  73.  
  74. if( i >= 0) /* Non Empty Line */
  75. {
  76. ++i;
  77. s[i] = '\n';
  78. ++i;
  79. s[i] = '\0';
  80. }
  81. return i;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement