sscanf() weired behaviour

Hi with the following code

int a, b;
while ((n = readline (connfd, buf, sizeof(buf)-1)) > 0)
{

buf[n] = '\\0'; 

if \(sscanf\(buf,"%d %d",&a,&b\) != 2\)
   snprintf \(buf, sizeof\(buf\), "data error\\r\\n"\);
  
 else
   \{
   printf\("\\nRecvd %d and %d",a,b\);
  snprintf \(buf, sizeof\(buf\), "%ld\\r\\n", a\+b\);\}

when i check the values "a" gets "0" whereas b gets the correct value. i tried this code outside it works fine out side in independent prog... I am using cygwin.
dataformat in buf = intSPACEint\r\n

---------- Post updated at 02:46 PM ---------- Previous update was at 02:39 PM ----------

ooh its working fine now with the above code.. i was using unsigned short a,b; instead of int ... and %u to get unsigned values....
However it is strnage it doenot use unsigned short ...
thanx for having a look

It expects integer size, and just giving it shorts doesn't warn it that you're giving it shorts. With &, you're giving it an address remember, so it can't know the size. So it crams 4 bytes of data into an address where you've got a 2-byte variable, overwriting 2 bytes of random data after it -- possibly your other variable there, producing the zero.

There are size qualifiers to the expressions if you want to give it anything other than an integer, see man 3 printf.