/**************************************************** * CP-I warmup 1999-2000 * Problem #8 ***************************************************/ /* * Question: * * 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_LENTH 100 main() { char str[100]; printf("Terminate input with \".\" in a new line\n"); printf("Give the input: \n"); while(1) { str[0]='\0'; scanf("%[^\n]",str); getchar(); if(!strcmp(str,".")) break; trim_string(str); if(str[0]) printf("%s\n",str); } } int trim_string(char *str) { int len,i,hook; len=strlen(str); for(i=0,hook=-1;i<len;i++) { if(str[i]!=' ' && str[i]!='\t') { hook=-1; continue; } if(hook==-1) hook=i; } if(hook!=-1) str[hook]='\0'; return 0; }