標籤:c 指標
有一定的難度,作者只做了前三題!
題目請見 http://download.csdn.net/download/wangpegasus/5701765
1、
char *find_char(char const *source, char const *chars){char *ptr;if(source != NULL && chars != NULL){for (; *source != '\0'; source++){for (ptr = (char *) chars; *ptr != '\0'; ptr++){if (*ptr = * source){return (char *)source;}}}}return NULL;}
2、
char *match(char *string, char *sub){while (*sub != '\0'){string++;sub++;if (*string != *sub){return NULL;}}return string;}int del_substr( char * str, char const *substr){char * ptr;ptr = NULL;if ( str == NULL && substr == NULL){return 0;}for (; *str != '\0'; str++){ptr = match(str, (char *)substr);if (ptr != NULL){break;}}while (*str++ = *ptr++){;}return 1;}
3、
void reverse_string(char *string){char temp;char * last;last = string;if (string != NULL){while (*last != '\0'){last++;}last--;while (string > last){temp = *last;*last = *string;*string = temp;string--;last++;}}}