>>103294571
>>103294613
>>103294639
// Helper function to read entire file content
// Returns a buffer pointer.
char* read_file_to_buffer(const char* filename) {
FILE* file;
char* buffer;
long file_size;
// Open the file using fopen_s for safety
errno_t err = fopen_s(&file, filename, "r");
if (err != 0 || file == NULL) {
perror("Error opening file");
return NULL;
}
// Determine file size
fseek(file, 0, SEEK_END);
file_size = ftell(file);
rewind(file);
// Allocate buffer and read file content
buffer = (char*)malloc(file_size + 1); // +1 for null terminator
if (buffer == NULL) {
perror("Error allocating memory");
fclose(file);
return NULL;
}
fread(buffer, 1, file_size, file);
buffer[file_size] = '\0'; // Null-terminate the string
fclose(file);
return buffer;
}
is this enough to just read the file including the \n inside a buffer
then i just write a loop to check if char == \n and process each line if i need to?
code was generated by chatgpt because i never worked with files in C so i wouldnt know