BugDict/C

BugDict/C

[C언어] "malloc(): invalid size (unsorted)" 해결

C 언어에서 발생하는 "malloc(): invalid size (unsorted)" 에러의 원인과 해결 방법을 설명합니다. 이 글에서는 문제 상황과 원인을 자세히 살펴보고, 해결 방법을 단계별로 설명합니다. 문제상황 에러가 발생한 코드: #include #include typedef struct { int a; int b; } SampleStruct; int main() { int n = 10; SampleStruct *arr = (SampleStruct *) malloc(n * sizeof(SampleStruct)); for (int i = 0; i

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 ..

BugDict/C

[C언어]"Error in `./a.out': malloc(): memory corruption (fast): 0x0000000001a1d030"해결

문제상황: C 언어로 개발하던 중 동적할당을 활용한 코드에서 에러가 발생했습니다. 에러가 발생한 코드: #include #include typedef struct { int id; char name[20]; } Employee; int main() { Employee* empList; int empCount = 5; empList = (Employee*)malloc(empCount * sizeof(Employee)); for (int i = 0; i

BugDict/C

[C언어] "Segmentation fault (core dumped)" 해결

문제상황: 다음 코드는 배열을 동적으로 할당한 후, 포인터를 사용하여 배열에 접근하려고 합니다. 하지만 실행시 "segmentation fault" 에러가 발생하며 프로그램이 종료됩니다. #include #include int main() { int *arr; int size; printf("Enter the size of the array: "); scanf("%d", &size); arr = (int *) malloc(size * sizeof(int)); for (int i = 0; i

BugDict/C

[C언어] "undefined reference to 'function_name'" 해결

문제상황: 실무에서 사용될 수 있는 C언어 코드를 작성 중 다음과 같은 에러가 발생했습니다. 아래 코드에서 에러가 발생한 부분과 에러 로그를 확인해봅시다. main.c #include #include "helper.h" int main() { int x = 5, y = 10; int result = add(x, y); printf("결과: %d\n", result); return 0; }helper.h #ifndef HELPER_H #define HELPER_H int add(int a, int b); #endif에러로그 내용: /tmp/ccvE6lJr.o: In function 'main': main.c:(.text+0x14): undefined reference to 'add&#..

Bug Detector
'BugDict/C' 카테고리의 글 목록