Code not running as expected!

  if (Serial.available())
  {
    count = 0;
    flag = 1;
    while (count < 12 && flag != 0)
    {
      input[count] = Serial.read();

You check whether there is Serial data available and if there is (it may only be 1 byte) you read from Serial 12 times. Have you tried printing each char as it is received ?