C program Write a program to remove trailing blanks and tabs. Write pseudo code
ID: 3751067 • Letter: C
Question
C program
Write a program to remove trailing blanks and tabs.
Write pseudo code for the program trim.c before trying to write the code itself. When you write trim.c, include the pseudo code in your comments at the beginning of the file. Compile it to be the executable program trim. Trailing blanks and tabs are defined as blanks and tabs that precede an character or an EOF to terminate a line, without any intervening characters of other kinds. You should copy a getline() function of the kind you see in the text to read in lines from stdin into an array, trim the line, and then write out the trimmed line to stdout, continuing until you encounter an EOF. Note: If there are 4 non-blank lines in the input to trim, there should be 4 lines in the output, but lines consisting of only blanks, and tabs, should NOT be output. The trim function should NOT affect any blanks or tabs that do not come at the end of the line.
Explanation / Answer
Please find the code below which trims leading and trailing blanks.
The below code also removes entire blank lines from output as well as required
Explain:
In the removetrail function, we go to the very end of the line and the trace back to the find the character which is not a space, tab and then replace it with 0.
This eliminates the trailing blanks in a line. For the empty lines whose length is 0, we simply skip that from output and thus removing it
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.