From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4286 invoked by alias); 11 Sep 2004 21:41:35 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 4278 invoked from network); 11 Sep 2004 21:41:34 -0000 Received: from unknown (HELO pcrz276.HRZ.Uni-Marburg.DE) (137.248.1.10) by sourceware.org with SMTP; 11 Sep 2004 21:41:34 -0000 Received: from pcrz276.HRZ.Uni-Marburg.DE (localhost [127.0.0.1]) by pcrz276.HRZ.Uni-Marburg.DE (8.12.3/8.12.3/Debian-6.6) with ESMTP id i8BLfX5W023481; Sat, 11 Sep 2004 23:41:33 +0200 Received: (from www-data@localhost) by pcrz276.HRZ.Uni-Marburg.DE (8.12.3/8.12.3/Debian-6.6) id i8BLfX6H023479; Sat, 11 Sep 2004 23:41:33 +0200 X-Authentication-Warning: pcrz276.HRZ.Uni-Marburg.DE: www-data set sender to reuti@staff.uni-marburg.de using -f Received: from 217.84.189.211 ( [217.84.189.211]) as user reuter@imap.staff.uni-marburg.de by home.staff.uni-marburg.de with HTTP; Sat, 11 Sep 2004 23:41:33 +0200 Message-ID: <1094938893.4143710d4d29e@home.staff.uni-marburg.de> Date: Sat, 11 Sep 2004 21:41:00 -0000 From: Reuti To: m.marcoll@web.de Cc: gcc-help@gcc.gnu.org Subject: Re: simple c question MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1 X-Originating-IP: 217.84.189.211 X-SW-Source: 2004-09/txt/msg00098.txt.bz2 Hi there, >///////////////////////////////////////////////// > >// string.h included of course... > >char * GetPath (char * string) >{ > char * path; > int i, pos=-1; > > for(i=0;string[i]!=0;i++) > { > if(string[i]=='/') > pos=i; > } > > if(pos==-1) > return NULL; > > strncpy(path, string, pos+1); > >return path; >} > >//////////////////////////////////////////// you are not allocating any memory for *path (it's just a pointer), where the strncpy could copy anythinkg to. void GetPath (char* string, char* result) { char *path; strcpy(result, string); path=strrchr(result, '/'); if (path==NULL) result[0]=0; else *(path+1)=0; } Greetings - Reuti PS: Once upon the time a lived at the Umstraße...