Understanding the rendering of raycasting on a flat screen

I have a misunderstanding about the flat screen raycasting formulas because my rendering is not what I expected, here are some parts of the code to show the projection formulas that I'm looking for. I wrote by myself.

while (++ i < limit) // limit == WIDTH of the screen
{
    w->cam-> spokes[i].startpoint = w-> cam-> position;
w-> cam-> rays[i].startpoint.color = 0xff0000;
w-> cam-> rays[i].endpoint.color = 0xff0000;
if (l == 1)
angle = (w-> cam-> angle + (w-> cam-> fov / 2) - (i * w-> cam-> fov / WIDTH_MM));
other
angle = (w-> cam-> angle + (w-> cam-> fov / 2) - (i * w-> cam-> fov / WIN_W));
dir.x = tcos (angle);
dir.y = tsin (angle);
if ((hit = intersection (w, l, & dir, i)))
w-> cam-> rays[i].endpoint = w-> cam-> intersection;
other
{
w-> cam-> rays[i].endpoint.x = w-> cam-> position.x + w-> cam-> raylength * dir.x;
w-> cam-> rays[i].endpoint.y = w-> cam-> position.y + w-> cam-> raylength * dir.y;
}

This is the code of the intersection function

int intersection (t_wolf3d * w, int i, t_vec2f * dir, int iter) {
int mapx;
int mapy;
unsigned int length;


length = -1;
while (++ length < w->cam-> raylength)
{
mapx = (int) (w-> cam-> position.x + (length * dir-> x));
mapy = (int) (w-> cam-> position.y + (length * dir-> y));
if ((mapy / BLOC_SIZE < w->map-> h && w-> map-> board[mapy / BLOC_SIZE]
                    [mapx / BLOC_SIZE]) || (i == 1 && mapy> = HEIGHT_MM))
{
w-> cam-> intersection.x = mapx;
w-> cam-> intersection.y = mapy;
return (1);
}
}
return (0);

}

I'm using this for projection, which is basically what I found by following @DM's instructions

                                if (l == 0)
{
raytravel.y = w-> cam-> rays[i].endpoint.y - w-> cam-> position.y;
raytravel.x = w-> cam-> rays[i].endpoint.x - w-> cam-> position.x;
depth = raytravel.x * tcos (w-> cam-> angle) + raytravel.y * tsin (w-> cam-> angle);
h_seen = dist_c * wall_h / depth;
y = cam_h - (h_seen / 2) - 1;
if (hit == 1)
while (++ y <(cam_h + (h_seen / 2)))
put_pixel_img (w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000);
}