Please Why is this segfaulting?

I have :

#include <GL/freeglut.h>
#include <stdio.h>

static void RenderSceneCB()
{
static GLclampf c = 0.0f;
glClearColor (c,c,c,c);
printf("%f/n",c);
c += 1.0f/256.0f;

if (c>=1.0f) {
c = 0.0f;
}

glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}

static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}

int main(int argc, char** argv)
{
void (*RenderSceneCB)();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA );

int width = 1920;
int height = 1080;
glutInitWindowSize(width,height);

int x = 200;
int y = 100;
glutInitWindowPosition(x,y);
int win = glutCreateWindow("Tutorial01");
printf("window id: %d/n",win);

GLclampf Red = 0.0f, Green = 0.0f, Blue = 0.0f, Alpha = 0.0f;
glClearColor (Red,Green,Blue,Alpha);

glutDisplayFunc(RenderSceneCB);
glutMainLoop();

return 0;

}

from the video at https://ogldev.org/www/tut`Preformatted text`orial01/tutorial01.html

I compiled with:
#! /bin/bash

CC=g++
LDFLAGS=`pkg-config --libs glew`
LDFLAGS="$LDFLAGS -lglut"

$CC tutorial01.cpp $LDFLAGS -o tutorial01

can anyone tell me why the segfault is happening and how to stop it?

Thanks.

Try compiling with warnings (-Wall). You should get something like:

prog.c: In function 'main':
prog.c:43:1: warning: 'RenderSceneCB' is used uninitialized [-Wuninitialized]
   43 | glutDisplayFunc(RenderSceneCB);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This line in main():

glutDisplayFunc(RenderSceneCB);

is using the value of the uninitialised local variable RenderSceneCB, not the address of the function RenderSceneCB.

Also:

foo.c:19:13: warning: 'InitializeGlutCallbacks' defined but not used [-Wunused-function]
   19 | static void InitializeGlutCallbacks()
      |             ^~~~~~~~~~~~~~~~~~~~~~~

If you’d used that function instead, it wouldn’t have crashed.

IOW, this is a problem with not understanding C, not an OpenGL problem.

Also: escape sequences such as "\n" use a backslash, not a forward slash. "/n" will print a slash followed by an ‘n’.