[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: [CPROG] gets strengen



>>>>> "Sune" == Sune Fischer <sslug@sslug> writes:

 Sune> Æhhh, faktisk er det delstrenge jeg vil søge efter.  En
 Sune> kommando kan nemlig være f.eks. "usermove e2e4" eller "feature
 Sune> done=1", så jeg kan ikke umiddelbart sammenligne "usermove" med
 Sune> "usermove e2e4" ;)

Så sammenligner du bare delstrengen. Hvis man forestiller sig at du
har et stort array de reserverede ord, hvor hvert element af array'et
er en struct med følgende indhold:

struct reserved_word {
        size_t length;
        char name[255];
};

hvor length så er længden på navnet.

Så kan du bare loope igennem array'et og sammenligne delstringen med
strncmp, ala: strcmp(teststring, array[i].name,array[i].length);

Når du så finder et match og har dekodet eventuelle parametre, så
flytter du bare teststring pointeren array[i].length frem så du næste
gang laver string compare på den næste delstring.

Alternativt til den her slags hjemmefiks laver du det rigtigt og
bruger flex og bison istedet ;)

 Sune> For lige at vende tilbage til mit oprindelige spørgsmål, er det
 Sune> så umuligt at finde længden af et dynamisk allokeret array?

Mener du strengen? så har du jo strlen.

-- 
Bye, Peter Korsgaard


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 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] *