🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #453

Re: Program crashes at end

#453
From: Emmanuel Delahaye
Date: Thu, 30 May 2002 19:23
50 lines
2172 bytes
In 'borland.public.cpp.turbocpp', "SKAS" <f93c0532@yahoo.com> wrote in
news:acv9rh$sopon$1@ID-31123.news.dfncis.de: 

> I've written a class for string datatype.  The program runs fine but

It doesn't works fine because it invokes an undefined behaviour.

<...>

> #include <iostream.h>
> #include <conio.h>
> #include <stdio.h>
> #include <string.h>
> 
> class string
> {
>  private:
>       char *head;
>       int len;
>  public:
>       string()
>    {
>    }

What is this one made for?
 
>   string(int l)
>   {
>    len=l;
>    head=new char[len];
>   }
> 
>   string(char a[])
>   {
>    strcpy(head,a);

'head' was never initialized. You probably want:

    len = strlen (a) + 1;
    head = new char[len];
    strcpy (head, a);

>   }

-- 
-ed- emdel at noos.fr
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/htm_cl/index.html
"Mal nommer les choses c'est ajouter du malheur au monde."
Albert Camus.
Technical Details
Message-ID: <Xns921ED99DC6F5Chsnoservernet@130.133.1.4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!e040.dhcp212-198-96.noos.FR!not-for-mail
References: <acv9rh$sopon$1@ID-31123.news.dfncis.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114af8,807a736b2ed72881
X-Google-Attributes: gid114af8,public
X-Google-Thread: 109fba,807a736b2ed72881
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,807a736b2ed72881
X-Google-Attributes: gid114592,public
X-Google-ArrivalTime: 2002-05-30 12:23:35 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!e040.dhcp212-198-96.noos.FR!not-for-mail
From: Emmanuel Delahaye <emdelNOSPAM@noos.fr>
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.turbocpp,comp.lang.c++
Subject: Re: Program crashes at end
Date: 30 May 2002 19:23:33 GMT
Organization: World Company
Lines: 50
Message-ID: <Xns921ED99DC6F5Chsnoservernet@130.133.1.4>
References: <acv9rh$sopon$1@ID-31123.news.dfncis.de>
NNTP-Posting-Host: e040.dhcp212-198-96.noos.fr (212.198.96.40)
X-Trace: fu-berlin.de 1022786613 31843174 212.198.96.40 (16 [98276])
User-Agent: Xnews/L5
X-face: &^QSr'ztO>vp64+s[Gbcxojr0l\;9Xx9**b0B^{6:(mEW?9fU}\rU]rdLYEKSD9a0ok=\,iXcNFm{qN_}nFV8#m+pQyV-g3kLi0+?]0RS@`jDAE[QlWO}I2|eq6#M~%iuJO2xz