BugDict/C
[C 언어] "Segmentation fault (core dumped)" 해결
문제상황: C 언어를 사용하여 파일을 읽고 쓰기를 하는 간단한 프로그램을 작성하는 과정에서, 파일을 열고 닫는 과정에서 에러가 발생했습니다. 아래는 에러가 발생한 코드와 해당 상황에 대한 설명입니다. #include #include int main() { FILE *file; char *buffer; size_t result; file = fopen("example.txt", "r"); if (file == NULL) { fputs("파일 열기 실패", stderr); exit(1); } fseek(file, 0, SEEK_END); long fileSize = ftell(file); rewind(file); buffer = (char *)malloc(sizeof(char) * fileSize); if ..