This may be somewhat of a "fix-my-code" question, but I've looked at documentation, examples, and dozens, of, related, questions, and though I logically understand more or less how it all works, I am having trouble translating it into a C sscanf()
format code. I am still relatively new to C, and am just starting to get into slightly beyond-simplistic stuff, and I am having trouble figuring out more complex format specifiers (ie. %[^...]
, etc.).
Anyways, here's what I have:
char user[EMAIL_LEN];
char site[EMAIL_LEN];
char domain[4];
if(sscanf(input, "%s@%s.%3s", user, site, domain) != 3){
printf("--ERROR: Invalid email address.--\n");
}
Why doesn't that work? I'm just trying to get a simple aaaa@bbbb.ccc
format, but for some reason sscanf(input, "%s@%s.%3s", user, site, domain)
always evaluates to 1
. Do I need to use some crazy %[^...]
magic for it to convert correctly? I've been messing with %[^@]
and that kind of thing, but I can't seem to make it work.
Any and all help is appreciated. Thanks!