-quzahCode:scanf("%[^(]%*c%[^0-9]%d%[^)]%*c%[^0-9]%d%[^-]%*c%[^0-9]%d", &areacode, &prefix, &suffix );
I saw this in a few posts ago... I was wondering how it works... I can kind of see but I have NEVER seen scanf() used like this before...
-LC
-quzahCode:scanf("%[^(]%*c%[^0-9]%d%[^)]%*c%[^0-9]%d%[^-]%*c%[^0-9]%d", &areacode, &prefix, &suffix );
I saw this in a few posts ago... I was wondering how it works... I can kind of see but I have NEVER seen scanf() used like this before...
-LC
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Eesh. Yeah that's horribly wrong. The original intent was to scanf into 3 variables, skipping everything else. At a glance, I simply omitted '*' in too many places. I also was under the impression that if it didn't encounter what it was looking for when using '*', it would just skip on to the next anyway. Looks like you do in fact learn something new every day.
I also drasticly over-complicated the issue. The theory was:
skip everything up to (
skip (
skip everything up to 0-9
read 0-9 into a variable
skip everything up to )
skip )
skip everything up to 0-9
read 0-9 into a variable
skip everything up to -
skip everything up to 0-9
read 0-9 into a variable
But as Salem demonstrated, you can simply do it in three reads. I over complicated the issue. (That and I commonly type while talking on the phone, which is not a GoodThing(TM) when trying to write code.)
Quzah.
Hope is the first step on the road to disappointment.