반응형
what is Segmentation fault (core dumped)?
I am trying to write a C program in linux that having sqrt of the argument, Here's the code:
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
int main(char *argv[]){
float k;
printf("this is consumer\n");
k=(float)sqrt(atoi(argv[1]));
printf("%s\n",k);
return 0;
}
After I type in my input at the "shell> " prompt, gcc gives me the following error:
Segmentation fault (core dumped)
"Segmentation fault" means that you tried to access memory that you do not have access to.
첫 번째 문제는 당신의 주장입니다.main
.그main
함수는 다음과 같아야 한다.int main(int argc, char *argv[])
를 체크해 주세요.argc
액세스하기 전에 적어도2개argv[1]
.
그리고, 당신이 지나가고 있으니까float
로.printf
(그건 그렇고, 이 경우엔,double
로 넘어가면printf
)를 사용합니다.%f
포맷 지정자.그%s
format specificate는 문자열용입니다.'\0'
- 종단 문자 배열).
ReferenceURL : https://stackoverflow.com/questions/19641597/what-is-segmentation-fault-core-dumped
반응형
'sourcecode' 카테고리의 다른 글
문자열 리터럴로 초기화되었지만 "char s[]"가 아닌 "char *s"에 쓸 때 세그멘테이션 장애가 발생하는 이유는 무엇입니까? (0) | 2022.08.12 |
---|---|
GUI 애플리케이션용 크로스 플랫폼 C 라이브러리 (0) | 2022.08.12 |
VueJs가 함수 내의 데이터 속성에 액세스할 수 없습니다. (0) | 2022.08.12 |
ATOMIC Integer의 실용적 용도 (0) | 2022.08.12 |
Java에서 개체 크기 계산 (0) | 2022.08.12 |