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 ) )
){
....
}
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)
){
}
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...
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') )
{
(...)
}
oder auch mit strchr: if ( strchr( "12ABC", data[6]) && strchr( "135", data[8]) )
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.