Rotating a point in space

Hello,
I am trying to rotate point p(3,0,0) with a vector dir(1,0,0) to a new direction dir2(0,1,0), wich means a 90º rotation around the z axis. But I'm having a problem with the code bellow wich returns me p2(0.875780;1.363946;-2.524413) instead of p2(0,3,0)... atm I can't locate the problem... does anyone have any idea?
Thanks

Code :
```CVector p(3,0,0),p2(0,0,0);
CVector dir(1,0,0);
CVector dir2(0,1,0);
float alfa,beta,gama;

alfa=dir.x-dir2.x;
gama=dir.y-dir2.y;
beta=dir.z-dir2.z;

float x,y,z;
float cos_alfa=cos(alfa);
float sin_alfa=sin(alfa);

float cos_beta=cos(beta);
float sin_beta=sin(beta);

float cos_gama=cos(gama);
float sin_gama=sin(gama);

x=p.x;
y=p.y;
z=p.z;

p2.x=x* ( cos_alfa * cos_gama ) +
y* ( cos_alfa * sin_gama * sin_beta - sin_alfa * cos_beta ) +
z* ( cos_alfa * sin_gama * sin_beta - sin_alfa * cos_beta );

p2.y=x* ( sin_alfa * cos_gama ) +
y* ( sin_alfa * sin_gama * sin_beta - cos_alfa * cos_beta ) +
z* ( sin_alfa * sin_gama * cos_beta - cos_alfa * cos_beta );

p2.z= -x * sin_alfa + z* ( cos_gama * sin_beta );

printf("Table:\n\n");
printf("Pos p(%f;%f;%f)\n",x,y,z);
printf("Dir v(%f;%f;%f)\n",dir.x,dir.y,dir.z);
printf("Dir v2(%f;%f;%f)\n\n",dir2.x,dir2.y,dir2.z);

printf("Alfa: %f\n",alfa);
printf("Gama: %f\n",gama);
printf("Beta: %f\n\n",beta);

printf("Pos p2(%f;%f;%f)\n\n",p2.x,p2.y,p2.z);```