[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Split char i C/C++



Bo Simonsen <sslug@sslug> skrev:

> Hvis man bruger seperations tegn er strtok jo god at bruge. fx.

Jeg tror aldrig strtok() er specielt god at bruge, den er vist skummel
nok til at det er bedre at lave sin egen udgave med rimelig opførsel.


> const char* test = "hej med dig";
> char* tp;
>
> for(tp = strtok(test, " \0");
>      tp;
>      tp = strtok(NULL, " \0"))
> {
>      printf("%s\n", tp);
> }

Funktionen strtok() virker ikke på konstante strenge, så det er nok
overvurderet med "const". Rent bortset fra at en tekststreng altid er
konstant, så det havde heller ikke virket uden "const".

Der indsættes automatisk nulafslutter i en tekststreng, så der er
ingen grund til "\0".


> Vil give
>
> hej
> med
> dig

Det tvivler jeg meget på.


Anders.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *