my code keeps throwing a segmentation fault from internal c libraries, my code is the following:
char *vertexShaderCode = (char *)calloc(1024, sizeof(char));
FILE *shaderFile;
shaderFile = fopen("./shaders/vertex.glsl", "r");
if(shaderFile)
{
//TODO: load file
for (char *line; !feof(shaderFile);)
{
fgets(line, 1024, shaderFile);
strcat(vertexShaderCode, line);
}
it is meant to load all the data from a file as a c string, line by line. can anyone help?
You want this:
You still need to make your that there is no buffer overflow. Possibly you need touse
reallocin order to expand the buffer if the initial length of the buffer is too small. I leave this as an exercise to you.Your wrong code: