一个看不懂的玩意儿……
老谭的书都看完了,在看C和指针,第4章《语句》习题7的答案没看明白,代码如下:
/*** Shrink runs of white space in the given string to a single space.*/#define NUL ’\0’voiddeblank( char *string ){ char *dest; char *src; int ch; /* ** Set source and destination pointers to beginning of the string, then ** move to 2nd character in string. */ src = string; dest = string++; /* ** Examine each character from the source string. */ while( (ch = *src++) != NUL ){ if( is_white( ch ) ){ /* ** We found white space. If we’re at the beginning of ** the string OR the previous char in the dest is not ** white space, store a blank. */ if( src == string || !is_white( dest[–1] ) ) *dest++ = ’ ’; } else { /* ** Not white space: just store it. */ *dest++ = ch; } } *dest = NUL;}intis_white( int ch ){return ch == ’ ’ || ch == ’\t’ || ch == ’\v’ || ch == ’\f’ || ch == ’\n’|| ch == ’\r’;}