Article View: be.comp.programming
Article #9415Re: [C++]: Splitten van een string ... Wat doe ik fout ???
From: Alain Cloet
Date: Mon, 29 Apr 2002 18:25
Date: Mon, 29 Apr 2002 18:25
62 lines
2620 bytes
2620 bytes
't was toch niet de bedoeling dat het door ons opgelost werd ? Enkele tips
toegevoegd ...(eentje is oplossing van de fout) ;-)
"Christof Laeremans" <christof_laeremans@hotmail.com> wrote in message
news:B8F31C5C.2817%christof_laeremans@hotmail.com...
> #include <iostream>
> #include <string>
>
> using namespace std;
>
>
> int main()
> {
> char string[80] = "VOLVO OPEL VOLKSWAGEN ";
> char *split;
> int start = 0;
> int spatie = 0;
> cout<<"Afdrukken van de string: "<<string<<endl;
> cout<<"lengte van de string is: "<<strlen(string)<<endl;
>
> for(int i = 0; i < strlen(string); i++)
> {
> if(string[i] == ' ')
> {
>
> cout<<"Er komt een spatie voor op positie: "<<i<<endl;
>
> spatie = i;
> split = new char[spatie - 1];
Te klein de eerste keer (na aanpassing fout ; kan wel werken, maar dan
eerder "toevallig") ; te groot anders...
>
> //Splitsen van de string
> for(int j = start; j < spatie+1; j++)
Waarom tot "spatie + 1", spatie is toch al voldoende ...
Je laatste char moet 0 zijn, dus moet je dit nog 'toevoegen' na de laatste
positie van de tijdelijke string die in onderstaande for-lus gemaakt
wordt...
> {
> split[j-start] = string[j];
> }
> start = spatie +1;
>
> cout<<split<<endl;
>
> delete[] split;
> }
> }
>
>
> }
Hopelijk lukt het hiermee... anders geef ik de letterlijke aanpassing wel...
Groeten,
Alain
Technical Details
Message-ID:
<khgz8.1798$X47.873206@iguano.antw.online.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!iguano.antw.online.be!not-for-mailReferences:
<B8F31C5C.2817%christof_laeremans@hotmail.com>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fcea4,966929e88b6c33f1 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2002-04-29 11:28:33 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!iguano.antw.online.be!not-for-mail From: "Alain Cloet" <nospam@tijd.com> Newsgroups: be.comp.programming References: <B8F31C5C.2817%christof_laeremans@hotmail.com> Subject: Re: [C++]: Splitten van een string ... Wat doe ik fout ??? Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Message-ID: <khgz8.1798$X47.873206@iguano.antw.online.be> Date: Mon, 29 Apr 2002 20:25:58 +0200 NNTP-Posting-Host: 62.112.10.219 X-Complaints-To: news-abuse@noc.online.be X-Trace: iguano.antw.online.be 1020104912 62.112.10.219 (Mon, 29 Apr 2002 20:28:32 MET DST) NNTP-Posting-Date: Mon, 29 Apr 2002 20:28:32 MET DST Organization: Customer of TijdNet