log Verknüpfung mit strcspn funktioniert nicht

Gast #2140709
Lesenswert?

Hallo,
ich wollte gerne mit Hilfe von strcspn() Daten mit Hilfe einer log 
Verknüpfung untersuchen. Sprich, wenn an Stelle 9 des Strings 1,35 und 
an Stelle 7 2,B,A oder 1, C auftaucht, soll das Programm reagieren. 
Eigentlich muss das so doch klappen?! Klappt aber nicht. Gruß

if(
strcspn( data, "135" ) == 9 &&
( strcspn( data, "2BA" ) == 7 || strcspn( data, "1C" )== 7 ) )
){
....
}
#2140745
Lesenswert?

Get span until character in string

Scans str1 for the first occurrence of any of the characters that are 
part of str2, returning the number of characters of str1 read before 
this first occurrence.

The search includes the terminating null-characters, so the function 
will return the length of str1 if none of the characters of str2 are 
found in str1.


insofern macht dieser code das selbe wie deiner:

if(strcspn( data, "135" ) == 9 &&strcspn( data, "12ABC" ) == 7)
){
}

...und immer im kopf behalten, dass das erste zeichen im string den 
index 0 hat...
also musst du das vermutlich eher so machen:

if(strcspn( data, "135" ) == 8 && strcspn( data, "12ABC" ) == 6)
){
}
Gast #2140847
Lesenswert?

hallo,
danke für die antwort. also wenn ich nur if(strcspn( data, "135" ) == 9) 
verwende klappt es. sobald ich noch zusätzliche log Verknüpfungen 
einbinden will, geht gar nichts mehr. mir ist die funktion von strcspn 
durchaus klar, allerdings kapier ich nicht, warum das nicht geht...
#2140873
Lesenswert?

ah ok.
also die "1" darf ja sowohl an stelle 6 und 9 vorkommen.

wenn jetzt eine 1 vorkommt, kommt bei beiden strcspn 6 raus.

wohl doch einfacher so:

if ( data[6] == '1' || data[6]=='2' || data[6]=='A || data[6]=='B' || 
data[6]=='C'') &&
      (data[8] == '1' || data[8]=='3' || data[8]=='5')  )
{
   (...)
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren