Clion can't read from a file
Answered
Hi. I just instaled Clion and want to read from a file. I have given you the relevant code and a picture of my folder. When I run the program by pressing the play button, I get the output “file can't be opened”. I do not know if the makeFile is relevent or not, therefor I give it to you as well. I have no clue how the makeFile works btw :)
int *memory;
int size;
size = 0;
FILE *fp = fopen("addresses.txt", "r");
char line[1000];
if (NULL == fp) {
printf("file can't be opened \n");
}
while(fgets(line, sizeof(line), fp) != NULL){
memory = realloc(memory, (size + 1) * sizeof(int));
size ++;
sscanf(line, "0x%x", &memory[size - 1]);
}
fclose(fp);

cmake_minimum_required(VERSION 3.26)
project(untitled C)
set(CMAKE_C_STANDARD 23)
add_executable(untitled main.c)
Please sign in to leave a comment.
Hello!
Please try placing the “addresses.txt” file into the “cmake-build-debug” folder, so that it is located next to the “untitled” executable.
Hello.
It turns out the problem was I did not have a direction. The name was "addresses" and not "addresses.txt". I have solved it now. But I do wanna thank you for reaching out to me :)