// HOWTO make C look like bash, or // HOWTO (ab)use shortcut operators, // by David Baird Thu Oct 6 14:28:09 MDT 2005 #include void weasel (char *buf) { unsigned int a, b, c; ((sscanf (buf, "%3u-%3u-%4u", &a, &b, &c) == 3) || (sscanf (buf, "%3u %3u %4u", &a, &b, &c) == 3) || (sscanf (buf, "(%3u) %3u-%4u", &a, &b, &c) == 3) || (sscanf (buf, "%3u%3u%4u", &a, &b, &c) == 3) || (printf ("You entered an invalid phone number\n") && 0)) && printf ("The phone number is (%03u) %03u-%04u\n", a, b, c); } int main () { weasel ("(505) 838-1234"); // The phone number is (505) 838-1234 weasel ("505 838 1234"); // The phone number is (505) 838-1234 weasel ("505-838-1234"); // The phone number is (505) 838-1234 weasel ("5058381234"); // The phone number is (505) 838-1234 weasel ("weasel"); // You entered an invalid phone number // *sigh* no stdio way to fix this... weasel ("1 2 3"); // The phone number is (001) 002-0003 return 0; }