This question was encountered during the last interview, and the computation was complete.CodeImplement it.
When judging the cyclic conditions, I made a low-level error in judging whether equal null was not referenced by the pointer. It must have been a fever for the past two days...
Write a little code every day and make a little progress every day. Come on ~
# Include <string. h> # include <stdio. h> # include <stdlib. h> bool contains (char * STR, char * value, int num) {If (* STR = NULL | * value = NULL) {printf ("Please check the parameters \ n"); Return true ;}for (; num> 0; ++ STR, -- num) {If (* Str) = (* value) return true;} return false;} void max_substring (char * DEST, char * & Pret, Int & COUNT) {pret = NULL; Count = 0; char * pstart = DEST, * pend, * pcurrent; I NT tmpcount = 0; while (* pstart! = NULL) {pcurrent = pstart; pend = pcurrent + 1; tmpcount = 1; while (* pend! = NULL &&! Contains (pcurrent, pend, tmpcount) {++ pend; ++ tmpcount;} If (tmpcount> count) {COUNT = tmpcount; pret = pcurrent ;} if (* pend = NULL) return; ++ pstart ;}} int main () {char Tom [] = "Hello World"; char * tmpj; int count; printf ("the original string is % s \ n function is used to find its largest non-duplicate substring \ n", Tom); max_substring (Tom, tmpj, count ); char result [sizeof (Tom)]; strncpy (result, tmpj, count); Result [count] = NULL; printf ("count is % d, and the string is % s \ n ", Count, result); System (" pause "); Return 0 ;}