smart parking system coding help needed

then

for(i = 0; i < 4 ;i++)
{
    if(slot[i])
  {
     char spot[4];
     sprintf(spot, "P%d,", i);
     strcat(str, spot);
  }
}