Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!pilchuck!dataio!gtenmc!csp From: csp@gtenmc.UUCP Newsgroups: comp.lang.c Subject: Extension to solution given to a novice Message-ID: <1140@gtenmc.UUCP> Date: 29 Apr 91 16:38:20 GMT Reply-To: csp@gtenmc.UUCP () Organization: GTE Telecom, Inc. Bothell, WA Lines: 41 > This proves without doubt 'Ignorance is NOT bliss'. followed by: > str[i] = malloc(strlen(gets(buff)+1)), The points you have raised are valid, but IMHO giving a routine which handles input with rigor, would even confuse the novice even further. But if you insist here is a routine which will handle the input will some rigor. Hope it satisfies your urge towards perfection. #include #include #define MEM_ERR 1 extern err_no; char *mygets(); char *mygets(l,t) unsigned l; char t; /* String terminator */ { char *ptr,c; c = getchar(); if (( int )c != -1 && c != t ) *( ptr = mygets( l + 1 , t )) = c; else { if (( ptr = malloc( l + 1 )) == ( char * ) NULL ) return( err_no = MEM_ERR , ( char * ) NULL ); *( ptr += l ) = 0; } return( ptr - 1 * ( l > 0 )); } C S Palkar