#include <stdio.h>#include<ctype.h>#include<stdlib.h>#defineBuf_len 20#defineBUF_INCR 10intMainvoid) {size_t Buf_len=Buf_len; Char*buffer = (Char*)malloc(Buf_len); Char*temp =NULL; Char*pbuffer1 =buffer; Char*pbuffer2 =NULL; printf ("enter:\n"); //Classic Code 1, dynamic allocation of memory during runtime while((*pbuffer1++=getchar ())! ='\ n') { if((pbuffer1-buffer) = =Buf_len) {Buf_len+=BUF_INCR; if(! (temp =realloc(Buffer,buf_len))) {printf ("bullshit!"); Exit (1); } pbuffer1= temp + (Pbuffer1-buffer); Buffer=temp; Temp=NULL; } } *pbuffer1 =' /'; Pbuffer1= Pbuffer2 =buffer; //Classic Code Snippet 2, set two pointers, manipulate the string, and the third pointer for full output. while((*pbuffer1)! =' /') { if(ispunct (*pbuffer1) | | Isspace (*pbuffer1)) { *pbuffer1++; Continue; } Else*pbuffer2++ = *pbuffer1++; } *pbuffer2 =' /'; printf ("with the spaces and punctuation removed, the string is now:\n%s\n", buffer); Free(buffer); return 0;}
C-pointer exercises to remove whitespace and punctuation strings