/* string2.c -- Compacting sequences of spaces in a string. We use two different methods */ #include #define MAXBUFF 128 int getline(char line[], int nmax); int compact1(char line[]); int compact2(char line[]); int main(void) { char buffer1[MAXBUFF]; char buffer2[MAXBUFF]; int len; len = getline(buffer1, MAXBUFF); printf("You entered : %s\n", buffer1); strcpy(buffer2,buffer1); printf("Which is : %s\n", buffer2); len=compact1(buffer1); printf("compact1: len=%d, %s\n",len, buffer1); len=compact2(buffer2); printf("compact2: len=%d, %s\n",len, buffer2); } int getline(char line[], int nmax) /* It prompts user and reads up to nmax * characters into line. It returns number * of characters read. ['\n' terminates the line] */ { int len; char c; len = 0; printf("Enter a string [CR to exit]: "); while(((c=getchar())!='\n') && len