Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Exercise 1-18. Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.*/
- #include <stdio.h>
- #define MAX 1000
- int untrail(char str[], int length);
- int main()
- {
- int length;
- length = 0;
- char str[MAX];
- while ((length = untrail (str, MAX)) > 0)
- printf ("%s\n", str);
- return 0;
- }
- int untrail(char str[], int length) {
- int c, i, j, flag;
- i = j = flag = 0;
- while ((c = getchar()) != EOF && c != '\n' && i < length - 1) {
- if (c == ' ' || c == '\t') {
- flag = 1;
- j += 1;
- } else {
- flag = 0;
- j = 0;
- }
- str[i++] = c;
- }
- if (flag) {
- str[i - j] = '\0';
- return j;
- } else {
- str[i] = '\0';
- return i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment